Create PPTX Charts in C#
Build .NET applications that create charts in presentation files using server-side Aspose.Slides APIs.
Create PPTX Charts Using C#
Use Aspose.Slides for .NET to create charts in PPTX presentations. Install the package from NuGet or use the following Package Manager Console command.
Command
PM> Install-Package Aspose.Slides.NETCreate a Chart in PPTX - C#
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var chart = slide.Shapes.AddChart(ChartType.ScatterWithSmoothLines, 0, 0, 400, 400);
var defaultWorksheetIndex = 0;
var chartDataWorkbook = chart.ChartData.ChartDataWorkbook;
chart.ChartData.Series.Clear();
chart.ChartData.Series.Add(chartDataWorkbook.GetCell(defaultWorksheetIndex, 1, 1, "Series 1"), chart.Type);
chart.ChartData.Series.Add(chartDataWorkbook.GetCell(defaultWorksheetIndex, 1, 3, "Series 2"), chart.Type);
var firstSeries = chart.ChartData.Series[0];
firstSeries.DataPoints.AddDataPointForScatterSeries(
chartDataWorkbook.GetCell(defaultWorksheetIndex, 2, 1, 1),
chartDataWorkbook.GetCell(defaultWorksheetIndex, 2, 2, 3));
firstSeries.DataPoints.AddDataPointForScatterSeries(
chartDataWorkbook.GetCell(defaultWorksheetIndex, 3, 1, 2),
chartDataWorkbook.GetCell(defaultWorksheetIndex, 3, 2, 10));
firstSeries.Type = ChartType.ScatterWithStraightLinesAndMarkers;
firstSeries.Marker.Size = 10;
firstSeries.Marker.Symbol = MarkerStyleType.Star;
var secondSeries = chart.ChartData.Series[1];
secondSeries.DataPoints.AddDataPointForScatterSeries(
chartDataWorkbook.GetCell(defaultWorksheetIndex, 2, 3, 5),
chartDataWorkbook.GetCell(defaultWorksheetIndex, 2, 4, 2));
secondSeries.DataPoints.AddDataPointForScatterSeries(
chartDataWorkbook.GetCell(defaultWorksheetIndex, 3, 3, 3),
chartDataWorkbook.GetCell(defaultWorksheetIndex, 3, 4, 1));
secondSeries.DataPoints.AddDataPointForScatterSeries(
chartDataWorkbook.GetCell(defaultWorksheetIndex, 4, 3, 2),
chartDataWorkbook.GetCell(defaultWorksheetIndex, 4, 4, 2));
secondSeries.DataPoints.AddDataPointForScatterSeries(
chartDataWorkbook.GetCell(defaultWorksheetIndex, 5, 3, 5),
chartDataWorkbook.GetCell(defaultWorksheetIndex, 5, 4, 1));
secondSeries.Marker.Size = 10;
secondSeries.Marker.Symbol = MarkerStyleType.Circle;
presentation.Save("AsposeScatterChart.pptx", SaveFormat.Pptx);How to Create Charts in PPTX Files Using C#
Create a chart in a PPTX presentation with Aspose.Slides for .NET in a few lines of code.
- Create a
Presentationobject. - Get the target slide from
presentation.Slides. - Call the
AddChartmethod to add a chart to the slide. - Add chart series and data points with
IChartDataWorkbook. - Save the presentation as a PPTX file.
System Requirements
Aspose.Slides for .NET supports major platforms and operating systems. Make sure that your environment includes the following prerequisites.
- A supported operating system with .NET or Mono installed.
- A development environment such as Microsoft Visual Studio.
- Aspose.Slides for .NET referenced in your project. Install it from NuGet or download it by using the Download button above.
Built with Aspose.Slides
Create PPTX Charts Online
The free Aspose.Slides Chart app is built with Aspose.Slides for .NET, the same API as the code above. Open it and see what the API can do with your own PPTX files.
- Runs in your browser, nothing to install.
- See how Aspose.Slides builds charts before you write code.
- Build a chart from Excel or table data.
- Download it as a PPTX file or an image.
What is PPTX File Format?
Files with the PPTX extension use the Office Open XML presentation format. A PPTX file can contain slides with text, charts, images, formatting, animations, and other presentation content.
Other Supported Chart Formats
Using C#, you can also create charts in other formats.