Create Charts in PowerPoint Presentations using C#

create charts in powerpoint ppt C#

Charts are used to summarize and visually represent the data within the PowerPoint presentations. Therefore, PowerPoint provides a wide range of chart types to visualize the data. Among all, the most commonly used chart types include pie charts, line charts, bar charts, histograms, stock charts, and etc. In this article, you will learn how to create these charts in PowerPoint presentations using C#.

C# API to Create Charts in PowerPoint

Aspose.Slides for .NET is a C# class library that lets you create and manipulate PowerPoint presentations from within .NET applications. Furthermore, the API allows you to create and add charts to the presentations seamlessly. Aspose.Slides for .NET can be downloaded as DLL or installed via NuGet.

PM> Install-Package Aspose.Slides

Create Column Chart in PowerPoint PPT using C#

In this section, you will learn how to create a column chart and add categories and series to populate that chart. The following are the steps to perform this operation.

For demonstration, the following code sample shows how to create a column chart in PowerPoint presentation using C#.

The following is the screenshot of the resultant column chart.

create column chart in powerpoint in C#

Create Scatter Chart in PowerPoint PPT using C#

The following are the steps to create a scatter chart in the PowerPoint presentation using C#.

  • Create a new presentation using the Presentation class.
  • Get the reference of the slides in the ISlide object.
  • Add a ScatterWithSmoothLines chart type with default data and get its reference in IChart object.
  • Access the chart data workbook into the IChartDataWorkbook object and clear the default series.
  • Add new series to the chart data.
  • Access each series into the IChartSeries object and add data points to the series.
  • Set the marker for the series using IChartSeries.Marker property.
  • Save the presentation using Presentation.Save(String, SaveFormat) method.

The following code sample shows how to create a scatter chart in PowerPoint presentations using C#.

The following screenshot shows the resultant scatter chart.

create scattered chart in powerpoint in C#

Create Pie Chart in PowerPoint PPT using C#

The following are the steps to create a pie chart in a PowerPoint presentation using C#.

The following code sample shows how to create a pie chart in PowerPoint presentation using C#.

The following is the screenshot of the generated pie chart.

create pie chart in powerpoint in C#

Add Histogram Chart in PowerPoint PPTX using C#

The following are the steps to create a histogram chart in PowerPoint presentations using Aspose.Slides for .NET.

  • Create an instance of the Presentation class.
  • Obtain a slide’s reference in the ISlide object by its index.
  • Add a Histogram chart with default data.
  • Clear the default series and categories.
  • Access the chart data workbook in the IChartDataWorkbook object.
  • Add new series and get its reference in the IChartSeries object.
  • Add data points to the series.
  • Set aggregation type of the chart axis.
  • Save the presentation using Presentation.Save(String, SaveFormat) method.

The following code sample shows how to create a histogram chart using C#.

The following is the screenshot of the created histogram chart.

create histogram chart in powerpoint in C#

Create a Stock Chart in PowerPoint using C#

Stock chart is also one of the commonly used chart types within PowerPoint presentations. The following are the steps to create a stock chart.

  • Create a new PowerPoint presentation using Presentation class.
  • Obtain slide’s reference in an ISlide object using the slide’s index.
  • Add OpenHighLowClose chart to the slide and get its reference in the IChart object.
  • Clear the default series and categories.
  • Access the chart data in IChartDataWorkbook object.
  • Add new series and categories to the chart.
  • Access each chart series and add data points.
  • Specify HiLowLines format.
  • Save the presentation using Presentation.Save(String, SaveFormat) method.

The following code sample shows how to add a stock chart to PowerPoint presentation using C#.

The following is the screenshot of the created stock chart.

create stock chart in powerpoint in C#

More Chart Types

In addition to the above-mentioned charts, there are other types of charts as well that you can add to the PowerPoint presentations. In order to read more about the supported chart types, you can visit this documentation article.

Get a Free API License

You can get a free temporary license in order to try the API without evaluation limitations.

Conclusion

In this article, you have learned how to create charts in PowerPoint presentations using C#. Furthermore, the step-by-step guide and code samples have shown how to add column charts, scatter charts, pie charts, histograms, and stock charts. You can explore more about Aspose.Slides for .NET using documentation.

See Also