Create or Update PowerPoint Presentation Charts in C# or .NET (2024)

Contents

[ Hide ]

Create Chart

Charts help people to quickly visualize data and gain insights, which may not be immediately obvious from a table or spreadsheet.

Why Create Charts?

Using charts, you get to

  • aggregate, condense, or summarize large amounts of data on a single slide in a presentation
  • expose patterns and trends in data
  • deduce the direction and momentum of data over time or with respect to a specific unit of measurement
  • spots outliers, aberrations, deviations, errors, nonsensical data, etc.
  • communicate or present complex data

In PowerPoint, you can create charts through the insert function, which provides templates used to design many types of charts. Using Aspose.Slides, you can create regular charts (based on popular chart types) and custom charts.

To allow you create charts, Aspose.Slides provides the ChartType enumeration under the Aspose.Slides.Charts namespace. The values under this enumeration correspond to different chart types.

Creating Normal Charts

  1. Create an instance of the Presentation class.
  2. Get a slide’s reference through its index.
  3. Add a chart with some data and specify your preferred chart type.
  4. Add a title for the chart.
  5. Access the chart data worksheet.
  6. Clear all the default series and categories.
  7. Add new series and categories.
  8. Add some new chart data for the chart series.
  9. Add a fill color for chart series.
  10. Add labels for the chart series.
  11. Write the modified presentation as a PPTX file.

This C# code shows you how to create a normal chart:

// Instantiates the Presentation class that represents a PPTX filePresentation pres = new Presentation();// Accesses the first slideISlide sld = pres.Slides[0];// Adds a chart with its default dataIChart chart = sld.Shapes.AddChart(ChartType.ClusteredColumn, 0, 0, 500, 500);// Sets the chart titlechart.ChartTitle.AddTextFrameForOverriding("Sample Title");chart.ChartTitle.TextFrameForOverriding.TextFrameFormat.CenterText = NullableBool.True;chart.ChartTitle.Height = 20;chart.HasTitle = true;// Sets the first series to show valueschart.ChartData.Series[0].Labels.DefaultDataLabelFormat.ShowValue = true;// Sets the index for the chart data sheetint defaultWorksheetIndex = 0;// Gets the chart data worksheetIChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook;// Deletes the default generated series and categorieschart.ChartData.Series.Clear();chart.ChartData.Categories.Clear();int s = chart.ChartData.Series.Count;s = chart.ChartData.Categories.Count;// Adds new serieschart.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);// Adds new categorieschart.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"));// Takes the first chart seriesIChartSeries series = chart.ChartData.Series[0];// Populates series dataseries.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, 20));series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 50));series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 30));// Sets the fill color for the seriesseries.Format.Fill.FillType = FillType.Solid;series.Format.Fill.SolidFillColor.Color = Color.Red;// Takes the second chart seriesseries = chart.ChartData.Series[1];// Populates series dataseries.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 2, 30));series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 2, 10));series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 2, 60));// Sets the fill color for seriesseries.Format.Fill.FillType = FillType.Solid;series.Format.Fill.SolidFillColor.Color = Color.Green;// Sets the first label to show Category nameIDataLabel lbl = series.DataPoints[0].Label;lbl.DataLabelFormat.ShowCategoryName = true;lbl = series.DataPoints[1].Label;lbl.DataLabelFormat.ShowSeriesName = true;// Sets the series to show the value for the third labellbl = series.DataPoints[2].Label;lbl.DataLabelFormat.ShowValue = true;lbl.DataLabelFormat.ShowSeriesName = true;lbl.DataLabelFormat.Separator = "/"; // Saves the PPTX file to diskpres.Save("AsposeChart_out.pptx", SaveFormat.Pptx);

Creating Scattered Charts

Scattered charts (also known as scattered plots or x-y graphs) are often used to check for patterns or demonstrate correlations between two variables.

You may want to use a scattered chart when

  • you have paired numerical data
  • you have 2 variables that pair well together
  • you want to determine whether 2 variables are related
  • you have an independent variable that has multiple values for a dependent variable

This C# code shows you how to create a scattered charts with a different series of markers:

Presentation pres = new Presentation();ISlide slide = pres.Slides[0];// Creates the default chartIChart chart = slide.Shapes.AddChart(ChartType.ScatterWithSmoothLines, 0, 0, 400, 400);// Gets the default chart data worksheet indexint defaultWorksheetIndex = 0;// Gets the chart data worksheetIChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook;// Deletes the demo serieschart.ChartData.Series.Clear();// Adds new serieschart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 1, 1, "Series 1"), chart.Type);chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 1, 3, "Series 2"), chart.Type);// Takes the first chart seriesIChartSeries series = chart.ChartData.Series[0];// Adds a new point (1:3) to the seriesseries.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 1), fact.GetCell(defaultWorksheetIndex, 2, 2, 3));// Adds a new point (2:10)series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 2), fact.GetCell(defaultWorksheetIndex, 3, 2, 10));// Changes the series typeseries.Type = ChartType.ScatterWithStraightLinesAndMarkers;// Changes the chart series markerseries.Marker.Size = 10;series.Marker.Symbol = MarkerStyleType.Star;// Takes second chart seriesseries = chart.ChartData.Series[1];// Adds a new point (5:2) to the chart seriesseries.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 2, 3, 5), fact.GetCell(defaultWorksheetIndex, 2, 4, 2));// Adds a new point (3:1)series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 3, 3, 3), fact.GetCell(defaultWorksheetIndex, 3, 4, 1));// Adds a new point (2:2)series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 4, 3, 2), fact.GetCell(defaultWorksheetIndex, 4, 4, 2));// Adds a new point (5:1)series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 5, 3, 5), fact.GetCell(defaultWorksheetIndex, 5, 4, 1));// Changes the chart series markerseries.Marker.Size = 10;series.Marker.Symbol = MarkerStyleType.Circle;// Saves the PPTX file to diskpres.Save("AsposeChart_out.pptx", SaveFormat.Pptx);

Creating Pie Charts

Pie charts are best used to show the part-to-whole relationship in data, especially when the data contains categorical labels with numeric values. However, if your data contains many parts or labels, you may want to consider using a bar chart instead.

  1. Create an instance of the Presentation class.
  2. Get a slide’s reference through its index.
  3. Add a chart with default data along with the desired type (in this case, ChartType.Pie).
  4. Access the chart data IChartDataWorkbook.
  5. Clear the default series and categories.
  6. Add new series and categories.
  7. Add new chart data for the chart series.
  8. Add new points for charts and add custom colors for the pie chart’s sectors.
  9. Set labels for series.
  10. Set leader lines for series labels.
  11. Set the rotation angle for pie chart slides.
  12. Write the modified presentation to a PPTX file

This C# code shows you how to create a pie chart:

// Instantiates a Presentation class that represents a PPTX filePresentation presentation = new Presentation();// Accesses the first slideISlide slides = presentation.Slides[0];// Adds a chart with its default dataIChart chart = slides.Shapes.AddChart(ChartType.Pie, 100, 100, 400, 400);// Sets the chart Titlechart.ChartTitle.AddTextFrameForOverriding("Sample Title");chart.ChartTitle.TextFrameForOverriding.TextFrameFormat.CenterText = NullableBool.True;chart.ChartTitle.Height = 20;chart.HasTitle = true;// Sets the first series to show valueschart.ChartData.Series[0].Labels.DefaultDataLabelFormat.ShowValue = true;// Sets the index for the chart data sheetint defaultWorksheetIndex = 0;// Gets the chart data worksheetIChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook;// Deletes the default generated series and categorieschart.ChartData.Series.Clear();chart.ChartData.Categories.Clear();// Adds new categorieschart.ChartData.Categories.Add(fact.GetCell(0, 1, 0, "First Qtr"));chart.ChartData.Categories.Add(fact.GetCell(0, 2, 0, "2nd Qtr"));chart.ChartData.Categories.Add(fact.GetCell(0, 3, 0, "3rd Qtr"));// Adds new seriesIChartSeries series = chart.ChartData.Series.Add(fact.GetCell(0, 0, 1, "Series 1"), chart.Type);// Populates the series dataseries.DataPoints.AddDataPointForPieSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, 20));series.DataPoints.AddDataPointForPieSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 50));series.DataPoints.AddDataPointForPieSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 30));// Not working in new version // Adding new points and setting sector color// series.IsColorVaried = true;chart.ChartData.SeriesGroups[0].IsColorVaried = true;IChartDataPoint point = series.DataPoints[0];point.Format.Fill.FillType = FillType.Solid;point.Format.Fill.SolidFillColor.Color = Color.Cyan;// Sets the Sector borderpoint.Format.Line.FillFormat.FillType = FillType.Solid;point.Format.Line.FillFormat.SolidFillColor.Color = Color.Gray;point.Format.Line.Width = 3.0;point.Format.Line.Style = LineStyle.ThinThick;point.Format.Line.DashStyle = LineDashStyle.DashDot;IChartDataPoint point1 = series.DataPoints[1];point1.Format.Fill.FillType = FillType.Solid;point1.Format.Fill.SolidFillColor.Color = Color.Brown;// Sets the Sector borderpoint1.Format.Line.FillFormat.FillType = FillType.Solid;point1.Format.Line.FillFormat.SolidFillColor.Color = Color.Blue;point1.Format.Line.Width = 3.0;point1.Format.Line.Style = LineStyle.Single;point1.Format.Line.DashStyle = LineDashStyle.LargeDashDot;IChartDataPoint point2 = series.DataPoints[2];point2.Format.Fill.FillType = FillType.Solid;point2.Format.Fill.SolidFillColor.Color = Color.Coral;// Sets the Sector borderpoint2.Format.Line.FillFormat.FillType = FillType.Solid;point2.Format.Line.FillFormat.SolidFillColor.Color = Color.Red;point2.Format.Line.Width = 2.0;point2.Format.Line.Style = LineStyle.ThinThin;point2.Format.Line.DashStyle = LineDashStyle.LargeDashDotDot;// Creates custom labels for each of categories for new seriesIDataLabel lbl1 = series.DataPoints[0].Label;// lbl.ShowCategoryName = true;lbl1.DataLabelFormat.ShowValue = true;IDataLabel lbl2 = series.DataPoints[1].Label;lbl2.DataLabelFormat.ShowValue = true;lbl2.DataLabelFormat.ShowLegendKey = true;lbl2.DataLabelFormat.ShowPercentage = true;IDataLabel lbl3 = series.DataPoints[2].Label;lbl3.DataLabelFormat.ShowSeriesName = true;lbl3.DataLabelFormat.ShowPercentage = true;// Sets the series to show leader lines for the chartseries.Labels.DefaultDataLabelFormat.ShowLeaderLines = true;// Sets the rotation angle for the pie chart sectorschart.ChartData.SeriesGroups[0].FirstSliceAngle = 180;// Saves the PPTX file to diskpresentation.Save("PieChart_out.pptx", SaveFormat.Pptx);

Creating Line Charts

Line charts (also known as a line graphs) are best used in situations where you want demonstrate changes in value over time. Using a line chart, you can compare lots of data at once, track changes and trends over time, highlight anomalies in data series, etc.

  1. Create an instance of thePresentationclass.
  2. Get a slide’s reference through its index.
  3. Add a chart with default data along with the desired type (in this case, ChartType.Line).
  4. Access the chart data IChartDataWorkbook.
  5. Clear the default series and categories.
  6. Add new series and categories.
  7. Add new chart data for the chart series.
  8. Write the modified presentation to a PPTX file

This C# code shows you how to create a line chart:

using (Presentation pres = new Presentation()){ IChart lineChart = pres.Slides[0].Shapes.AddChart(ChartType.Line, 10, 50, 600, 350); pres.Save("lineChart.pptx", SaveFormat.Pptx);}

By default, points on a line chart are joined by straight continuous lines. If you want to the points to be joined by dashes instead, you can specify your preferred dash type this way: xxx

IChart lineChart = pres.Slides[0].Shapes.AddChart(ChartType.Line, 10, 50, 600, 350);foreach (IChartSeries series in lineChart.ChartData.Series){ series.Format.Line.DashStyle = LineDashStyle.Dash;}

Creating Tree Map Charts

Tree map charts are best used for sales data when you want to show the relative size of data categories and (at the same time) quickly draw attention to items that are large contributors to each category.

  1. Create an instance of thePresentationclass.
  2. Get a slide’s reference through its index.
  3. Add a chart with default data along with the desired type (in this case, ChartType.TreeMap).
  4. Access the chart data IChartDataWorkbook.
  5. Clear the default series and categories.
  6. Add new series and categories.
  7. Add new chart data for the chart series.
  8. Write the modified presentation to a PPTX file

This C# code shows you how to create a tree map chart:

using (Presentation presentation = new Presentation()){IChart chart = presentation.Slides[0].Shapes.AddChart(Aspose.Slides.Charts.ChartType.Treemap, 50, 50, 500, 400);chart.ChartData.Categories.Clear();chart.ChartData.Series.Clear();IChartDataWorkbook wb = chart.ChartData.ChartDataWorkbook;wb.Clear(0);// Branch 1IChartCategory leaf = chart.ChartData.Categories.Add(wb.GetCell(0, "C1", "Leaf1"));leaf.GroupingLevels.SetGroupingItem(1, "Stem1");leaf.GroupingLevels.SetGroupingItem(2, "Branch1");chart.ChartData.Categories.Add(wb.GetCell(0, "C2", "Leaf2"));leaf = chart.ChartData.Categories.Add(wb.GetCell(0, "C3", "Leaf3"));leaf.GroupingLevels.SetGroupingItem(1, "Stem2");chart.ChartData.Categories.Add(wb.GetCell(0, "C4", "Leaf4"));// Branch 2leaf = chart.ChartData.Categories.Add(wb.GetCell(0, "C5", "Leaf5"));leaf.GroupingLevels.SetGroupingItem(1, "Stem3");leaf.GroupingLevels.SetGroupingItem(2, "Branch2");chart.ChartData.Categories.Add(wb.GetCell(0, "C6", "Leaf6"));leaf = chart.ChartData.Categories.Add(wb.GetCell(0, "C7", "Leaf7"));leaf.GroupingLevels.SetGroupingItem(1, "Stem4");chart.ChartData.Categories.Add(wb.GetCell(0, "C8", "Leaf8"));IChartSeries series = chart.ChartData.Series.Add(Aspose.Slides.Charts.ChartType.Treemap);series.Labels.DefaultDataLabelFormat.ShowCategoryName = true;series.DataPoints.AddDataPointForTreemapSeries(wb.GetCell(0, "D1", 4));series.DataPoints.AddDataPointForTreemapSeries(wb.GetCell(0, "D2", 5));series.DataPoints.AddDataPointForTreemapSeries(wb.GetCell(0, "D3", 3));series.DataPoints.AddDataPointForTreemapSeries(wb.GetCell(0, "D4", 6));series.DataPoints.AddDataPointForTreemapSeries(wb.GetCell(0, "D5", 9));series.DataPoints.AddDataPointForTreemapSeries(wb.GetCell(0, "D6", 9));series.DataPoints.AddDataPointForTreemapSeries(wb.GetCell(0, "D7", 4));series.DataPoints.AddDataPointForTreemapSeries(wb.GetCell(0, "D8", 3));series.ParentLabelLayout = ParentLabelLayoutType.Overlapping;presentation.Save("Treemap.pptx", SaveFormat.Pptx);}

Creating Stock Charts

  1. Create an instance of thePresentationclass.
  2. Get a slide’s reference through its index.
  3. Add a chart with default data along with the desired type (ChartType.OpenHighLowClose).
  4. Access the chart data IChartDataWorkbook.
  5. Clear the default series and categories.
  6. Add new series and categories.
  7. Add new chart data for the chart series.
  8. Specify HiLowLines format.
  9. Write the modified presentation to a PPTX file

Sample C# code used to create a stock chart:

using (Presentation pres = new Presentation()){IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.OpenHighLowClose, 50, 50, 600, 400, false); IChartDataWorkbook wb = chart.ChartData.ChartDataWorkbook;chart.ChartData.Categories.Add(wb.GetCell(0, 1, 0, "A"));chart.ChartData.Categories.Add(wb.GetCell(0, 2, 0, "B"));chart.ChartData.Categories.Add(wb.GetCell(0, 3, 0, "C"));chart.ChartData.Series.Add(wb.GetCell(0, 0, 1, "Open"), chart.Type);chart.ChartData.Series.Add(wb.GetCell(0, 0, 2, "High"), chart.Type);chart.ChartData.Series.Add(wb.GetCell(0, 0, 3, "Low"), chart.Type);chart.ChartData.Series.Add(wb.GetCell(0, 0, 4, "Close"), chart.Type);IChartSeries series = chart.ChartData.Series[0];series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 1, 1, 72));series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 2, 1, 25));series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 3, 1, 38));series = chart.ChartData.Series[1];series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 1, 2, 172));series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 2, 2, 57));series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 3, 2, 57));series = chart.ChartData.Series[2];series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 1, 3, 12));series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 2, 3, 12));series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 3, 3, 13));series = chart.ChartData.Series[3];series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 1, 4, 25));series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 2, 4, 38));series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 3, 4, 50));chart.ChartData.SeriesGroups[0].UpDownBars.HasUpDownBars = true;chart.ChartData.SeriesGroups[0].HiLowLinesFormat.Line.FillFormat.FillType = FillType.Solid;foreach (IChartSeries ser in chart.ChartData.Series){ser.Format.Line.FillFormat.FillType = FillType.NoFill;}pres.Save("Stock-chart.pptx", SaveFormat.Pptx);}

Creating Box and Whisker Charts

  1. Create an instance of thePresentationclass.
  2. Get a slide’s reference through its index.
  3. Add a chart with default data along with the desired type (ChartType.BoxAndWhisker).
  4. Access the chart data IChartDataWorkbook.
  5. Clear the default series and categories.
  6. Add new series and categories.
  7. Add new chart data for the chart series.
  8. Write the modified presentation to a PPTX file

This C# code shows you how to create a box and whisker chart:

public static void Run(){using (Presentation pres = new Presentation("test.pptx")){IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.BoxAndWhisker, 50, 50, 500, 400);chart.ChartData.Categories.Clear();chart.ChartData.Series.Clear();IChartDataWorkbook wb = chart.ChartData.ChartDataWorkbook;wb.Clear(0);chart.ChartData.Categories.Add(wb.GetCell(0, "A1", "Category 1"));chart.ChartData.Categories.Add(wb.GetCell(0, "A2", "Category 1"));chart.ChartData.Categories.Add(wb.GetCell(0, "A3", "Category 1"));chart.ChartData.Categories.Add(wb.GetCell(0, "A4", "Category 1"));chart.ChartData.Categories.Add(wb.GetCell(0, "A5", "Category 1"));chart.ChartData.Categories.Add(wb.GetCell(0, "A6", "Category 1"));IChartSeries series = chart.ChartData.Series.Add(ChartType.BoxAndWhisker);series.QuartileMethod = QuartileMethodType.Exclusive;series.ShowMeanLine = true;series.ShowMeanMarkers = true;series.ShowInnerPoints = true;series.ShowOutlierPoints = true;series.DataPoints.AddDataPointForBoxAndWhiskerSeries(wb.GetCell(0, "B1", 15));series.DataPoints.AddDataPointForBoxAndWhiskerSeries(wb.GetCell(0, "B2", 41));series.DataPoints.AddDataPointForBoxAndWhiskerSeries(wb.GetCell(0, "B3", 16));series.DataPoints.AddDataPointForBoxAndWhiskerSeries(wb.GetCell(0, "B4", 10));series.DataPoints.AddDataPointForBoxAndWhiskerSeries(wb.GetCell(0, "B5", 23));series.DataPoints.AddDataPointForBoxAndWhiskerSeries(wb.GetCell(0, "B6", 16));pres.Save("BoxAndWhisker.pptx", SaveFormat.Pptx);}}

Creating Funnel Charts

  1. Create an instance of thePresentationclass.
  2. Get a slide’s reference through its index.
  3. Add a chart with default data along with the desired type (ChartType.Funnel).
  4. Write the modified presentation to a PPTX file

This C# code shows you how to create a funnel chart:

public static void Run(){using (Presentation pres = new Presentation("test.pptx")){IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.Funnel, 50, 50, 500, 400);chart.ChartData.Categories.Clear();chart.ChartData.Series.Clear();IChartDataWorkbook wb = chart.ChartData.ChartDataWorkbook;wb.Clear(0);chart.ChartData.Categories.Add(wb.GetCell(0, "A1", "Category 1"));chart.ChartData.Categories.Add(wb.GetCell(0, "A2", "Category 2"));chart.ChartData.Categories.Add(wb.GetCell(0, "A3", "Category 3"));chart.ChartData.Categories.Add(wb.GetCell(0, "A4", "Category 4"));chart.ChartData.Categories.Add(wb.GetCell(0, "A5", "Category 5"));chart.ChartData.Categories.Add(wb.GetCell(0, "A6", "Category 6"));IChartSeries series = chart.ChartData.Series.Add(ChartType.Funnel);series.DataPoints.AddDataPointForFunnelSeries(wb.GetCell(0, "B1", 50));series.DataPoints.AddDataPointForFunnelSeries(wb.GetCell(0, "B2", 100));series.DataPoints.AddDataPointForFunnelSeries(wb.GetCell(0, "B3", 200));series.DataPoints.AddDataPointForFunnelSeries(wb.GetCell(0, "B4", 300));series.DataPoints.AddDataPointForFunnelSeries(wb.GetCell(0, "B5", 400));series.DataPoints.AddDataPointForFunnelSeries(wb.GetCell(0, "B6", 500));pres.Save("Funnel.pptx", SaveFormat.Pptx);}}

Creating Sunburst Charts

  1. Create an instance of thePresentationclass.
  2. Get a slide’s reference through its index.
  3. Add a chart with default data along with the desired type (in this case, ChartType.sunburst).
  4. Write the modified presentation to a PPTX file

This C# code shows you how to create a sunburst chart:

public static void Run(){using (Presentation pres = new Presentation("test.pptx")){IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.Sunburst, 50, 50, 500, 400);chart.ChartData.Categories.Clear();chart.ChartData.Series.Clear();IChartDataWorkbook wb = chart.ChartData.ChartDataWorkbook;wb.Clear(0);// Branch 1IChartCategory leaf = chart.ChartData.Categories.Add(wb.GetCell(0, "C1", "Leaf1"));leaf.GroupingLevels.SetGroupingItem(1, "Stem1");leaf.GroupingLevels.SetGroupingItem(2, "Branch1");chart.ChartData.Categories.Add(wb.GetCell(0, "C2", "Leaf2"));leaf = chart.ChartData.Categories.Add(wb.GetCell(0, "C3", "Leaf3"));leaf.GroupingLevels.SetGroupingItem(1, "Stem2");chart.ChartData.Categories.Add(wb.GetCell(0, "C4", "Leaf4"));// Branch 2leaf = chart.ChartData.Categories.Add(wb.GetCell(0, "C5", "Leaf5"));leaf.GroupingLevels.SetGroupingItem(1, "Stem3");leaf.GroupingLevels.SetGroupingItem(2, "Branch2");chart.ChartData.Categories.Add(wb.GetCell(0, "C6", "Leaf6"));leaf = chart.ChartData.Categories.Add(wb.GetCell(0, "C7", "Leaf7"));leaf.GroupingLevels.SetGroupingItem(1, "Stem4");chart.ChartData.Categories.Add(wb.GetCell(0, "C8", "Leaf8"));IChartSeries series = chart.ChartData.Series.Add(ChartType.Sunburst);series.Labels.DefaultDataLabelFormat.ShowCategoryName = true;series.DataPoints.AddDataPointForSunburstSeries(wb.GetCell(0, "D1", 4));series.DataPoints.AddDataPointForSunburstSeries(wb.GetCell(0, "D2", 5));series.DataPoints.AddDataPointForSunburstSeries(wb.GetCell(0, "D3", 3));series.DataPoints.AddDataPointForSunburstSeries(wb.GetCell(0, "D4", 6));series.DataPoints.AddDataPointForSunburstSeries(wb.GetCell(0, "D5", 9));series.DataPoints.AddDataPointForSunburstSeries(wb.GetCell(0, "D6", 9));series.DataPoints.AddDataPointForSunburstSeries(wb.GetCell(0, "D7", 4));series.DataPoints.AddDataPointForSunburstSeries(wb.GetCell(0, "D8", 3));pres.Save("Sunburst.pptx", SaveFormat.Pptx);}}

Creating Histogram Charts

  1. Create an instance of thePresentationclass.
  2. Get a slide’s reference through its index.
  3. Add some chart with some data and specify your preferred chart type (ChartType.Histogram in this case).
  4. Access the chart data IChartDataWorkbook.
  5. Clear the default series and categories.
  6. Add new series and categories.
  7. Write the modified presentation to a PPTX file

This C# code shows you how to create an histogram chart:

public static void Run(){using (Presentation pres = new Presentation("test.pptx")){IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.Histogram, 50, 50, 500, 400);chart.ChartData.Categories.Clear();chart.ChartData.Series.Clear();IChartDataWorkbook wb = chart.ChartData.ChartDataWorkbook;wb.Clear(0);IChartSeries series = chart.ChartData.Series.Add(ChartType.Histogram);series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A1", 15));series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A2", -41));series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A3", 16));series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A4", 10));series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A5", -23));series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A6", 16));chart.Axes.HorizontalAxis.AggregationType = AxisAggregationType.Automatic;pres.Save("Histogram.pptx", SaveFormat.Pptx);}}

Creating Radar Charts

  1. Create an instance of thePresentationclass
  2. Get a slide’s reference through its index.
  3. Add a chart with some data and specify your preferred chart type (ChartType.Radar in this case).
  4. Write the modified presentation to a PPTX file

This C# code shows you how to create a radar chart:

using (Presentation presentation = new Presentation()){ presentation.Slides[0].Shapes.AddChart(ChartType.Radar, 20, 20, 400, 300); presentation.Save("Radar-chart.pptx", SaveFormat.Pptx);}

Creating Multi Category Charts

  1. Create an instance of thePresentationclass.
  2. Get a slide’s reference through its index.
  3. Add a chart with default data along with the desired type (ChartType.ClusteredColumn).
  4. Access the chart data IChartDataWorkbook.
  5. Clear the default series and categories.
  6. Add new series and categories.
  7. Add new chart data for the chart series.
  8. Write the modified presentation to a PPTX file.

This C# code shows you how to create a multicategory chart:

Presentation pres = new Presentation();ISlide slide = pres.Slides[0];IChart ch = pres.Slides[0].Shapes.AddChart(ChartType.ClusteredColumn, 100, 100, 600, 450);ch.ChartData.Series.Clear();ch.ChartData.Categories.Clear();IChartDataWorkbook fact = ch.ChartData.ChartDataWorkbook;fact.Clear(0);int defaultWorksheetIndex = 0;IChartCategory category = ch.ChartData.Categories.Add(fact.GetCell(0, "c2", "A"));category.GroupingLevels.SetGroupingItem(1, "Group1");category = ch.ChartData.Categories.Add(fact.GetCell(0, "c3", "B"));category = ch.ChartData.Categories.Add(fact.GetCell(0, "c4", "C"));category.GroupingLevels.SetGroupingItem(1, "Group2");category = ch.ChartData.Categories.Add(fact.GetCell(0, "c5", "D"));category = ch.ChartData.Categories.Add(fact.GetCell(0, "c6", "E"));category.GroupingLevels.SetGroupingItem(1, "Group3");category = ch.ChartData.Categories.Add(fact.GetCell(0, "c7", "F"));category = ch.ChartData.Categories.Add(fact.GetCell(0, "c8", "G"));category.GroupingLevels.SetGroupingItem(1, "Group4");category = ch.ChartData.Categories.Add(fact.GetCell(0, "c9", "H"));// Adds the SeriesIChartSeries series = ch.ChartData.Series.Add(fact.GetCell(0, "D1", "Series 1"), ChartType.ClusteredColumn);series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D2", 10));series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D3", 20));series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D4", 30));series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D5", 40));series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D6", 50));series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D7", 60));series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D8", 70));series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D9", 80));// Saves presentation with chartpres.Save("AsposeChart_out.pptx", Aspose.Slides.Export.SaveFormat.Pptx);

Creating Map Charts

A map chart is a visualization of an area containing data. Map charts are best used to compare data or values across geographical regions.

This C# code shows you how to create a map chart:

using (Presentation pres = new Presentation()){ IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.Map, 50, 50, 500, 400); pres.Save("mapChart.pptx", SaveFormat.Pptx);}

Creating Combination Charts

A combination chart (or combo chart) is a chart that combines two or more charts on a single graph. Such a chart allows you to highlight, compare, or review differences between two (or more) sets of data. This way, you see the relationship (if any) between the sets of data.

Create or Update PowerPoint Presentation Charts in C# or .NET (1)

This C# code shows you how to create a combination chart in PowerPoint:

private static void CreateComboChart(){ using (Presentation pres = new Presentation()) { IChart chart = CreateChart(pres.Slides[0]); AddFirstSeriesToChart(chart); AddSecondSeriesToChart(chart); pres.Save("combo-chart.pptx", SaveFormat.Pptx); }}private static IChart CreateChart(ISlide slide){ IChart chart = slide.Shapes.AddChart(ChartType.ClusteredColumn, 50, 50, 500, 400); chart.ChartData.Series.Clear(); chart.ChartData.Categories.Clear(); IChartDataWorkbook workbook = chart.ChartData.ChartDataWorkbook; const int worksheetIndex = 0; chart.ChartData.Series.Add(workbook.GetCell(worksheetIndex, 0, 1, "Series 1"), chart.Type); chart.ChartData.Series.Add(workbook.GetCell(worksheetIndex, 0, 2, "Series 2"), chart.Type); chart.ChartData.Categories.Add(workbook.GetCell(worksheetIndex, 1, 0, "Caetegoty 1")); chart.ChartData.Categories.Add(workbook.GetCell(worksheetIndex, 2, 0, "Caetegoty 2")); chart.ChartData.Categories.Add(workbook.GetCell(worksheetIndex, 3, 0, "Caetegoty 3")); IChartSeries series = chart.ChartData.Series[0]; series.DataPoints.AddDataPointForBarSeries(workbook.GetCell(worksheetIndex, 1, 1, 20)); series.DataPoints.AddDataPointForBarSeries(workbook.GetCell(worksheetIndex, 2, 1, 50)); series.DataPoints.AddDataPointForBarSeries(workbook.GetCell(worksheetIndex, 3, 1, 30)); series = chart.ChartData.Series[1]; series.DataPoints.AddDataPointForBarSeries(workbook.GetCell(worksheetIndex, 1, 2, 30)); series.DataPoints.AddDataPointForBarSeries(workbook.GetCell(worksheetIndex, 2, 2, 10)); series.DataPoints.AddDataPointForBarSeries(workbook.GetCell(worksheetIndex, 3, 2, 60)); return chart;}private static void AddFirstSeriesToChart(IChart chart){ IChartDataWorkbook workbook = chart.ChartData.ChartDataWorkbook; const int worksheetIndex = 0; IChartSeries series = chart.ChartData.Series.Add(workbook.GetCell(worksheetIndex, 0, 3, "Series 3"), ChartType.ScatterWithSmoothLines); series.DataPoints.AddDataPointForScatterSeries( workbook.GetCell(worksheetIndex, 0, 1, 3), workbook.GetCell(worksheetIndex, 0, 2, 5)); series.DataPoints.AddDataPointForScatterSeries( workbook.GetCell(worksheetIndex, 1, 3, 10), workbook.GetCell(worksheetIndex, 1, 4, 13)); series.DataPoints.AddDataPointForScatterSeries( workbook.GetCell(worksheetIndex, 2, 3, 20), workbook.GetCell(worksheetIndex, 2, 4, 15)); series.PlotOnSecondAxis = true;}private static void AddSecondSeriesToChart(IChart chart){ IChartDataWorkbook workbook = chart.ChartData.ChartDataWorkbook; const int worksheetIndex = 0; IChartSeries series = chart.ChartData.Series.Add(workbook.GetCell(worksheetIndex, 0, 5, "Series 4"), ChartType.ScatterWithStraightLinesAndMarkers); series.DataPoints.AddDataPointForScatterSeries( workbook.GetCell(worksheetIndex, 1, 3, 5), workbook.GetCell(worksheetIndex, 1, 4, 2)); series.DataPoints.AddDataPointForScatterSeries( workbook.GetCell(worksheetIndex, 1, 5, 10), workbook.GetCell(worksheetIndex, 1, 6, 7)); series.DataPoints.AddDataPointForScatterSeries( workbook.GetCell(worksheetIndex, 2, 5, 15), workbook.GetCell(worksheetIndex, 2, 6, 12)); series.DataPoints.AddDataPointForScatterSeries( workbook.GetCell(worksheetIndex, 3, 5, 12), workbook.GetCell(worksheetIndex, 3, 6, 9)); series.PlotOnSecondAxis = true;}

Updating Charts

  1. Instantiate a Presentation class that represents the presentation containing the chart.
  2. Get a slide’s reference through its index.
  3. Traverse through all shapes to find the desired chart.
  4. Access the chart data worksheet.
  5. Modify the chart data series data by changing series values.
  6. Add a new series and populate the data in it.
  7. Write the modified presentation as a PPTX file.

This C# code shows you how to update a chart:

// Instantiates a Presentation class that represents a PPTX filePresentation pres = new Presentation("ExistingChart.pptx");// Accesses the first slideMarkerISlide sld = pres.Slides[0];// Adds a chart with default dataIChart chart = (IChart)sld.Shapes[0];// Sets the index for the chart data sheetint defaultWorksheetIndex = 0;// Gets the chart data worksheetIChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook;// Changes the chart Category Namefact.GetCell(defaultWorksheetIndex, 1, 0, "Modified Category 1");fact.GetCell(defaultWorksheetIndex, 2, 0, "Modified Category 2");// Takes the first chart seriesIChartSeries series = chart.ChartData.Series[0];// Updates the series datafact.GetCell(defaultWorksheetIndex, 0, 1, "New_Series1");// Modifying series nameseries.DataPoints[0].Value.Data = 90;series.DataPoints[1].Value.Data = 123;series.DataPoints[2].Value.Data = 44;// Take Second chart seriesseries = chart.ChartData.Series[1];// Now updating series datafact.GetCell(defaultWorksheetIndex, 0, 2, "New_Series2");// Modifying series nameseries.DataPoints[0].Value.Data = 23;series.DataPoints[1].Value.Data = 67;series.DataPoints[2].Value.Data = 99;// Now, Adding a new serieschart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 3, "Series 3"), chart.Type);// Take 3rd chart seriesseries = chart.ChartData.Series[2];// Now populating series dataseries.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 3, 20));series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 3, 50));series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 3, 30));chart.Type = ChartType.ClusteredCylinder;// Save presentation with chartpres.Save("AsposeChartModified_out.pptx", SaveFormat.Pptx);

Setting Data Range for Charts

  1. Instantiate a Presentation class that represents the presentation containing the chart.
  2. Get a slide’s reference through its index.
  3. Traverse through all shapes to find the desired chart.
  4. Access the chart data and set the range.
  5. Save the modified presentation as a PPTX file.

This C# code shows you how to set the data range for a chart:

// Instantiates a Presentation class that represents a PPTX filePresentation presentation = new Presentation("ExistingChart.pptx");// Accesses the first slideMarker and adds a chart with default dataISlide slide = presentation.Slides[0];IChart chart = (IChart)slide.Shapes[0];chart.ChartData.SetRange("Sheet1!A1:B4");presentation.Save("SetDataRange_out.pptx", SaveFormat.Pptx);

Using Default Markers in Charts

When you use a default marker in charts, each chart series get different default marker symbols automatically.

This C# code shows you how to set a chart series market automatically:

using (Presentation pres = new Presentation()){ ISlide slide = pres.Slides[0]; IChart chart = slide.Shapes.AddChart(ChartType.LineWithMarkers, 10, 10, 400, 400); chart.ChartData.Series.Clear(); chart.ChartData.Categories.Clear(); IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook; chart.ChartData.Series.Add(fact.GetCell(0, 0, 1, "Series 1"), chart.Type); IChartSeries series = chart.ChartData.Series[0]; chart.ChartData.Categories.Add(fact.GetCell(0, 1, 0, "C1")); series.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 1, 1, 24)); chart.ChartData.Categories.Add(fact.GetCell(0, 2, 0, "C2")); series.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 2, 1, 23)); chart.ChartData.Categories.Add(fact.GetCell(0, 3, 0, "C3")); series.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 3, 1, -10)); chart.ChartData.Categories.Add(fact.GetCell(0, 4, 0, "C4")); series.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 4, 1, null)); chart.ChartData.Series.Add(fact.GetCell(0, 0, 2, "Series 2"), chart.Type); // Takes the second chart series IChartSeries series2 = chart.ChartData.Series[1]; // Populates the series data series2.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 1, 2, 30)); series2.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 2, 2, 10)); series2.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 3, 2, 60)); series2.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 4, 2, 40)); chart.HasLegend = true; chart.Legend.Overlay = false; pres.Save("DefaultMarkersInChart.pptx", SaveFormat.Pptx);}
Create or Update PowerPoint Presentation Charts in C# or .NET (2024)

FAQs

How do you change the data source for a chart in PowerPoint? ›

Click on the chart. On the ribbon, click Chart Design and then click Select Data. This selects the data range of the chart and displays the Select Data Source dialog box. To edit a legend series, in the Legend entries (series) box, click the series you want to change.

How to make a dynamic chart in ppt? ›

How to make dynamic chart in pptx
  1. Open your PowerPoint presentation and select the slide where you want to add the chart.
  2. Click on the 'Insert' tab in the ribbon, then click on 'Chart'.
  3. Choose the type of chart you want to insert, then click 'OK'.
  4. An Excel worksheet will open. ...
  5. Close the Excel worksheet when you're done.

How do you create a new chart in PowerPoint? ›

To create a simple chart from scratch in PowerPoint, click Insert > Chart and pick the chart you want. Click Insert > Chart. Click the chart type and then double-click the chart you want. Tip: For help deciding which chart is best for your data, see Available chart types.

How do you update a chart? ›

Select the chart. Select Chart Design > Edit Data in Excel. Excel opens and displays the data table for the chart.

Why won t my PowerPoint chart update? ›

Using Insert | Object and choosing Link will often cause this kind of problems. Instead select the area you want to link to in Excel, copy, switch to PowerPoint and Paste Special, Link. If you're linking to part of a spreadsheet rather than a chart, it's a good idea to select the area and give it a range name.

What is the best chart to use in PowerPoint to show data changes over a period of time or comparisons among items? ›

Column charts are useful for showing data changes over a period of time or for illustrating comparisons among items. In column charts, categories are along the horizontal axis and values along the vertical axis.

How do you embed chart data in PowerPoint? ›

Embed an Excel Chart in Powerpoint
  1. Click the Insert tab.
  2. Expand the Text group.
  3. Select Object.
  4. Select the Create from file radio button.
  5. Click the Browse button.
  6. Select the file with the chart you want to import.
  7. Click OK.
  8. (Optional) Check the Link check box.

What does the chart elements option allow you to change in PowerPoint? ›

Click the Chart Elements button and check or uncheck the elements you want to add or remove, such as Chart Title. Different chart types have different elements, styles, and filters. To add data labels, you check Data Labels.

What is a dynamic chart? ›

A dynamic chart is a special chart in Excel which updates itself when the range of the chart is updated. In static charts, the chart does not change itself when the range is updated. To create a dynamic chart in Excel, the range or the source of data needs to be dynamic in nature.

Can you animate a chart in PowerPoint? ›

I needed to find a way to present the data in a way that was clear, compelling and accessible to the audience given the venue. Many people don't know this, but animations in PowerPoint can be applied to charts, and with some basic configuration, you can use these features to tell amazing stories.

Can PowerPoint be dynamic? ›

With Dynamic PowerPoint, you can display real-time information on any screen, whether it's in a boardroom, a classroom, or a public space. Our flexible and visually stunning plugins can be customized to fit the exact needs of your setting. Want to display the weather, time, and news updates in an airport?

What kind of charts are available in Microsoft PowerPoint? ›

Types of PowerPoint charts and functions
  • Gantt chart.
  • Bar chart.
  • Pie chart.
  • Line chart.
  • Area diagram.
  • Waterfall diagram.
  • Scatter diagram.
  • Mekko diagram.
Jan 25, 2021

Is a PowerPoint chart updated automatically whenever the changes? ›

Answer: A chart must be located in a specific cell or at a specific address range. Any data changed in the worksheet is automatically updated in the chart. Dragging a chart object to a new location on the worksheet will change the data in the worksheet.

How do I update an embedded Excel chart in PowerPoint? ›

Update linked Excel data in PowerPoint

In PowerPoint, right-click the data and select Update Link.

How do you edit chart labels in PowerPoint? ›

On the Layout tab, in the Labels group, click Data Labels, and then click the option that you want. For additional data label options, click More Data Label Options, click Label Options if it's not selected, and then select the options that you want.

Top Articles
Latest Posts
Article information

Author: Lidia Grady

Last Updated:

Views: 6190

Rating: 4.4 / 5 (65 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Lidia Grady

Birthday: 1992-01-22

Address: Suite 493 356 Dale Fall, New Wanda, RI 52485

Phone: +29914464387516

Job: Customer Engineer

Hobby: Cryptography, Writing, Dowsing, Stand-up comedy, Calligraphy, Web surfing, Ghost hunting

Introduction: My name is Lidia Grady, I am a thankful, fine, glamorous, lucky, lively, pleasant, shiny person who loves writing and wants to share my knowledge and understanding with you.