We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Radar Chart example

I was trying to create a radar chart in aspose slides but received an error (primary axis not configured)


Does someone have a coded example in C# or VB.Net that shows how I can build a radar chart?

Thanks in advance


Hi Francis,


Thank you for your interest in Aspose.Slides.

I have observed your comments and like to request you to please try using following sample code on your end to serve the purpose. I have also attached generated output file (RadarTest.pptx) for your kind reference.

Presentation pres = new
Presentation();<o:p></o:p>

ISlide slide = pres.Slides[0];

IChart chart = slide.Shapes.AddChart(ChartType.Radar, 0, 0, 500, 500);

chart.ChartData.Series[0].DataPoints[0].Value.Data = 2.5;

chart.ChartData.Series[0].DataPoints[1].Value.Data = 1.3;

chart.ChartData.Series[0].DataPoints[2].Value.Data = 0.7;

chart.ChartData.Categories[0].Value = 0.5;

chart.ChartData.Categories[1].Value = 1.5;

chart.ChartData.Categories[2].Value = 2.5;

pres.Save(@"D:\RadarTest.pptx", SaveFormat.Pptx);


I hope this will be helpful. Please share if I may help you further in this regard.

Best Regards,

Hi Adnan,


Thank you for the example. I’m trying to dynamically add multiple categories, but I get a strange error. When I just do the below , I receive an error.

chart.ChartData.Series[0].DataPoints[0].Value.Data = 2.5;
chart.ChartData.Series[0].DataPoints[1].Value.Data = 1.3;
chart.ChartData.Series[0].DataPoints[2].Value.Data = 0.7;

chart.ChartData.Series[1].DataPoints[0].Value.Data = 1.5;
chart.ChartData.Series[1].DataPoints[1].Value.Data = 4.3;
chart.ChartData.Series[1].DataPoints[2].Value.Data = 3.7;


When I try to add the datapoints dynamically, I receive another error:
foreach (var itemVal in item.ValueList)
{
valIdx++; chart.ChartData.Series[valIdx].DataPoints.AddDataPointForRadarSeries((double)itemVal.Value);
}

ERROR:
DataSourceTypeForValues != DataSourceType.DoubleLiterals and so value cannot be of System.Double type.

Hi Francis,


I have observed your comments and like to share with you that there is only one series but you are trying to add values for second series which does not exist. To work with more than one series, another series needs to be added first, I request you to please try using following sample code on your end to serve the purpose.

Presentation pres = new
Presentation();<o:p></o:p>

//Access first slide

ISlide sld = pres.Slides[0];

// Add chart with default data

IChart chart = sld.Shapes.AddChart(ChartType.Radar, 0, 0, 500, 500);

//Set first series to Show Values

chart.ChartData.Series[0].Labels.DefaultDataLabelFormat.ShowValue = true;

//Setting the index of chart data sheet

int defaultWorksheetIndex = 0;

//Getting the chart data worksheet

IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook;

//Delete default generated series and categories

chart.ChartData.Series.Clear();

chart.ChartData.Categories.Clear();

int s = chart.ChartData.Series.Count;

s = chart.ChartData.Categories.Count;

//Adding new series

chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.Type);

chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.Type);

//Adding new categories

chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1"));

chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2"));

chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3"));

//Take first chart series

IChartSeries series = chart.ChartData.Series[0];

//Now populating series data

series.DataPoints.AddDataPointForRadarSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, 20));

series.DataPoints.AddDataPointForRadarSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 50));

series.DataPoints.AddDataPointForRadarSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 30));

//Setting fill color for series

series.Format.Fill.FillType = FillType.Solid;

series.Format.Fill.SolidFillColor.Color = Color.Red;

//Take second chart series

series = chart.ChartData.Series[1];

//Now populating series data

series.DataPoints.AddDataPointForRadarSeries(fact.GetCell(defaultWorksheetIndex, 1, 2, 30));

series.DataPoints.AddDataPointForRadarSeries(fact.GetCell(defaultWorksheetIndex, 2, 2, 10));

series.DataPoints.AddDataPointForRadarSeries(fact.GetCell(defaultWorksheetIndex, 3, 2, 60));

//Setting fill color for series

series.Format.Fill.FillType = FillType.Solid;

series.Format.Fill.SolidFillColor.Color = Color.Green;

//Save presentation with chart

pres.Save(@"D:\Test.pptx" , SaveFormat.Pptx);


I hope this will be helpful. Please share if I may help you further in this regard.

Best Regards,