How to create the PowerPoint radar chart in C# and VB.NET
This article explains how to create a radar chart in PowerPoint using Presentation library.
What is a radar chart
Radar charts compare the aggregate values of several data series by plotting the values of each category along a separate axis, which starts in the center of the chart and ends at the outer ring.
Radar chart created using Presentation library
Steps to create radar chart in PowerPoint using Presentation library:
- Initialize chart
Create a chart object by calling the slide.Charts.AddChart method and specify the chart type to OfficeChartType.Radar enum value.
//Create the chart IPresentationChart chart = slide.Charts.AddChart(100, 10, 700, 500); //Set chart type to radar chart.ChartType = OfficeChartType.Radar;
- Assign data
Set a range of data from the worksheet to chart’s DataRange property. To plot the series values in column and categories in row, set chart’s IsSeriesInRows property to false.
//Set region of chart data chart.DataRange = chart.ChartData[1, 1, 6, 2]; //Set chart series in column for assigned data region chart.IsSeriesInRows = false;
- Apply basic chart elements
Add the basic elements like chart title, data labels, and legend.
- ChartTitle of chart object.
- Set DataLabels via DefaultDataPoint.
- Set TRUE to chart’s HasLegend property to show the legend.
//Apply chart elements //Set chart title chart.ChartTitle = "Radar Chart"; //Set legend chart.HasLegend = false; //Set Datalabels IOfficeChartSerie serie = chart.Series[0]; serie.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
Other property that is applicable for a radar chart is HasRadarAxisLablesHasRadarAxisLables
NOTE: Applying properties apart from the mentioned property may throw exception or the changes will not be reflected in the output document because those, properties are not related to radar chart.
Applying properties apart from the mentioned property may throw exception or the changes will not be reflected in the output document because those, properties are not related to radar chart
To learn more about creating charts with various settings using Presentation library, please refer to the documentation.
The following C# and VB.NET complete code snippet shows the creation of radar chart using Presentation library.
C#
using Syncfusion.Presentation; using Syncfusion.OfficeChart; using System.IO; namespace ChartSample { class Program { static void Main(string[] args) { //Create an instance for PowerPoint using (IPresentation pptxDoc = Presentation.Create()) { //Add a blank slide to Presentation ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank); //Adds chart to the slide with position and size IPresentationChart chart = slide.Charts.AddChart(100, 10, 700, 500); chart.ChartType = OfficeChartType.Radar; //Assign data chart.DataRange = chart.ChartData[1, 1, 6, 2]; chart.IsSeriesInRows = false; //Set data to the chart RowIndex, columnIndex and data chart.ChartData.SetValue(1, 1, "Food"); chart.ChartData.SetValue(1, 2, "Count"); chart.ChartData.SetValue(2, 1, "Fruits"); chart.ChartData.SetValue(3, 1, "Vegitables"); chart.ChartData.SetValue(4, 1, "Dairy"); chart.ChartData.SetValue(5, 1, "Proptein"); chart.ChartData.SetValue(6, 1, "Grains"); chart.ChartData.SetValue(1, 2, "Percentage"); chart.ChartData.SetValue(2, 2, "36"); chart.ChartData.SetValue(3, 2, "14"); chart.ChartData.SetValue(4, 2, "13"); chart.ChartData.SetValue(5, 2, "28"); chart.ChartData.SetValue(6, 2, "9"); //Apply chart elements //Set chart title chart.ChartTitle = "Radar Chart"; //Set legend chart.HasLegend = false; //Set Datalabels IOfficeChartSerie serie = chart.Series[0]; serie.DataPoints.DefaultDataPoint.DataLabels.IsValue = true; //Saving and closing the presentation Stream stream = File.Create("Output.pptx"); pptxDoc.Save(stream); } } } }
VB
Imports Syncfusion.Presentation Imports Syncfusion.OfficeChart Imports System.IO Namespace ChartSample Class Program Public Shared Sub Main(ByVal args As String()) 'Create an instance for PowerPoint Dim pptxDoc As IPresentation = Presentation.Create() 'Add a blank slide to Presentation Dim slide As ISlide = pptxDoc.Slides.Add(SlideLayoutType.Blank) 'Adds chart to the slide with position and size Dim chart As IPresentationChart = slide.Charts.AddChart(100, 10, 700, 500) chart.ChartType = OfficeChartType.Radar 'Assign data chart.DataRange = chart.ChartData(1, 1, 6, 2) chart.IsSeriesInRows = False 'Set data to the chart- RowIndex, columnIndex and data chart.ChartData.SetValue(1, 1, "Food") chart.ChartData.SetValue(1, 2, "Count") chart.ChartData.SetValue(2, 1, "Fruits") chart.ChartData.SetValue(3, 1, "Vegitables") chart.ChartData.SetValue(4, 1, "Dairy") chart.ChartData.SetValue(5, 1, "Proptein") chart.ChartData.SetValue(6, 1, "Grains") chart.ChartData.SetValue(1, 2, "Percentage") chart.ChartData.SetValue(2, 2, "36") chart.ChartData.SetValue(3, 2, "14") chart.ChartData.SetValue(4, 2, "13") chart.ChartData.SetValue(5, 2, "28") chart.ChartData.SetValue(6, 2, "9") 'Apply chart elements 'Set chart title chart.ChartTitle = "Radar Chart" 'Set legend chart.HasLegend = False 'Set Datalabels Dim serie As IOfficeChartSerie = chart.Series(0) serie.DataPoints.DefaultDataPoint.DataLabels.IsValue = True 'Saving and closing the presentation Dim stream As Stream = File.Create("Output.pptx") pptxDoc.Save(stream) End Sub End Class End Namespace