Create Chart

Create Chart

Aspose.Slides for .NET lets developers add custom charts into slides from scratch. This topic, explains how to create normal and scatter charts with multiple series from scratch using Aspose.Slides for .NET. Aspose.Slides for .NET is works independently of Aspose.Cells for .NET for chart creation. This article explains how to create different types of charts:

  • Create normal charts.
  • Create a scatter chart with multiple series and different series markers.

Create Normal Chart

Aspose.Slides for .NET has provided the simplest API for creating charts in an easy way. To create a chart in a slide, please follow the steps below:

  1. Create an instance of the Presentation class.
  2. Obtain the reference of a slide by index.
  3. Add a chart with default data along with the desired type.
  4. Add a chart title.
  5. Access the chart data worksheet.
  6. Clear all the default series and categories.
  7. Add new series and categories.
  8. Add new chart data for chart series.
  9. Add fill color for chart series.
  10. Adding chart series labels.
  11. Write the modified presentation as a PPTX file.

The following example shows how to create a normal Chart.

Create Scattered Chart

The following code is used to create a scatter chart with different series of markers.

Create Pie Chart

Aspose.Slides for .NET provides a simple API for creating and filling pie charts in an easy way. To create a chart on a slide:

  1. Create an instance of the Presentation class.
  2. Obtain a slide’s reference by its index.
  3. Add a chart with default data along with the desired type (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

The following code is used to create a chart.

Create Tree Map Chart

Aspose.Slides for .NET provides a simple API for creating Tree Map charts in an easy way. To create a chart on a slide:

  1. Create an instance of the Presentation class.
  2. Obtain a slide’s reference by its index.
  3. Add a chart with default data along with the desired type (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

The following code is used to create a chart.

Create Stock Chart

Aspose.Slides for .NET provides a simple API for creating Stock charts in an easy way. To create a chart on a slide:

  1. Create an instance of the Presentation class.
  2. Obtain a slide’s reference by 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. specifies HiLowLines format.
  9. Write the modified presentation to a PPTX file

The following code is used to create a chart.

Create Box and Whisker Chart

Aspose.Slides for .NET provides a simple API for creating Box and Whisker charts in an easy way. To create a chart on a slide:

  1. Create an instance of the Presentation class.
  2. Obtain a slide’s reference by 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

The following code is used to create a chart.

Create Funnel Chart

Aspose.Slides for .NET provides a simple API for creating Funnel charts in an easy way. To create a chart on a slide:

  1. Create an instance of the Presentation class.
  2. Obtain a slide’s reference by 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

The following code is used to create a chart.

Create Sunburst Chart

Aspose.Slides for .NET provides a simple API for creating Sunburst charts in an easy way. To create a chart on a slide:

  1. Create an instance of the Presentation class.
  2. Obtain a slide’s reference by its index.
  3. Add a chart with default data along with the desired type (ChartType.sunburst).
  4. Write the modified presentation to a PPTX file

The following code is used to create a chart.

Create Histogram Chart

Aspose.Slides for .NET provides a simple API for creating Histogram charts in an easy way. To create a chart on a slide:

  1. Create an instance of the Presentation class.
  2. Obtain a slide’s reference by its index.
  3. Add a chart with default data along with the desired type (ChartType.Histogram).
  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

The following code is used to create a chart.

Create Multi Category Chart

Aspose.Slides for .NET provides a simple API for creating a multi category chart. To create a chart on a slide:

  1. Create an instance of the Presentation class.
  2. Obtain a slide’s reference by 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.

The following code is used to create a chart.

Update Chart

Aspose.Slides for .NET has provided the simplest API to update charts in an easiest way. To update a chart in a slide:

  • Open an instance of Presentation class containing the chart.
  • Obtain the reference of a slide by using its Index.
  • Traverse through all shapes to find the desired chart.
  • Access the chart data worksheet.
  • Modify the chart data series data by changing series values.
  • Adding a new series and populating data inside it.
  • Write the modified presentation as a PPTX file.

The code examples that follow how to update a chart.

Setting Data Range for Chart

Aspose.Slides for .NET has provided the simplest API to set the data range for a chart in an easiest way. To set the data range for a chart:

  • Open an instance of Presentation class containing the chart.
  • Obtain the reference of a slide by using its Index.
  • Traverse through all shapes to find the desired chart.
  • Access the chart data and set the range.
  • Save the modified presentation as a PPTX file.

The code examples that follow how to update a chart.

Default Markers in Chart

Aspose.Slides for .NET provides a simple API to set the chart series marker automatically. In the following feature, every chart series will get different default marker symbols automatically.

Below code example shows how to set the chart series marker automatically.