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

Free Support Forum - aspose.com

Sample code for Pie Chart

Hi,

I would just like for a sample code on how to supply data for a pie chart.

Thank you.

Hi Joemelle,

Thanks for your inquiry. Please see Working with Charts section of documentation and try using the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = builder.InsertChart(ChartType.Pie, 432, 252);
Chart chart = shape.Chart;

ChartSeriesCollection seriesColl = chart.Series;
seriesColl.Clear();

string[] categories = new string[] { "Grapefruit", "Oranges", "Plums", "Pears", "Apples" };
// Specify all values as 20%
ChartSeries series = seriesColl.Add("Imported Fruits", categories, new double[] { 2, 2, 2, 2, 2 });

ChartDataLabelCollection dataLabelCollection = series.DataLabels;

ChartDataLabel chartDataLabel00 = dataLabelCollection.Add(0);
ChartDataLabel chartDataLabel01 = dataLabelCollection.Add(1);
ChartDataLabel chartDataLabel02 = dataLabelCollection.Add(2);
ChartDataLabel chartDataLabel03 = dataLabelCollection.Add(3);
ChartDataLabel chartDataLabel04 = dataLabelCollection.Add(4);

chartDataLabel00.ShowCategoryName = true;
chartDataLabel01.ShowCategoryName = true;
chartDataLabel02.ShowCategoryName = true;
chartDataLabel03.ShowCategoryName = true;
chartDataLabel04.ShowCategoryName = true;

chart.Legend.Position = LegendPosition.Left;

doc.Save(MyDir + @"15.12.0.docx");

Hope, this helps.

Best regards,