Create a Chart in a Microsoft PowerPoint Presentation
Contents
[
Hide
]
Charts are visual representations of data that are widely used in presentations. This article shows the code for create a chart in Microsoft PowerPoint programmatically by using VSTO and Aspose.Slides for Java.
Creating a Chart
The code examples below describe the process of adding a simple 3D clustered column chart using VSTO. You create a presentation instance, add a default chart to it. Then use Microsoft Excel workbook to access and modify chart data along with setting chart properties. Lastly, save the presentation.
VSTO Example
Using VSTO, the following steps are performed:
- Create an instance of a Microsoft PowerPoint presentation.
- Add a blank slide to the presentation.
- Add a 3D clustered column chart and access it.
- Create a new Microsoft Excel Workbook instance and load chart data.
- Access the chart data worksheet using Microsoft Excel Workbook instancefromworkbook.
- Set the chart range in the worksheet and remove series 2 and 3 from the chart.
- Modify the chart category data in the chart data worksheet.
- Modify chart series 1 data in the chart data worksheet.
- Now, access the chart title and setthefontrelatedproperties.
- Access the chart value axis and set the major unit, minor units, max value and min values.
- Access the chart depth or series axis and remove that as in this example, onlyoneserieisused.
- Now, set the chart rotation angles in X and Y direction.
- Save the presentation.
- Close the instances of Microsoft Excel and PowerPoint.
The output presentation, created with VSTO
Aspose.Slides for Java Example
Using Aspose.Slides for Java, the following steps are performed:
- Create an instance of a Microsoft PowerPoint presentation.
- Add a blank slide to the presentation.
- Add a 3D clustered column chart and access that.
- Access the chart data worksheet using a Microsoft Excel Workbook instancefromworkbook.
- Remove unused series 2 and 3.
- Access chart categories and modify the labels.
- Accesseries1 and modify the series values.
- Now, access the chart title and set the font properties.
- Access the chart value axis and set the major unit, minor units, max value and min values.
- Now, set the chart rotation angles in X and Y direction.
- Save the presentation to PPTX format.
The output presentation, created with Aspose.Slides