Create Charts in PowerPoint Presentations using Java

create charts in powerpoint ppt java

Charts are used to summarize and visually represent the data within the presentations. To visualize the data, MS PowerPoint provides a wide range of chart types. 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 charts in PowerPoint presentations using Java.

Java API to Create Charts in PowerPoint

In order to create different types of charts in presentations, we will use Aspose.Slides for Java. The said API lets you create and manipulate PowerPoint presentations from within your Java applications. Furthermore, it allows you to create and add charts to the presentations seamlessly. You can either download the API or install it using the following Maven configurations.

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>http://repository.aspose.com/repo/</url>
</repository>
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-slides</artifactId>
    <version>21.7</version>
    <classifier>jdk16</classifier>
</dependency>

Create Column Chart in PowerPoint PPT using Java

The following are the steps to create a column chart in a PowerPoint presentation using Java.

  • First, create an instance of the Presentation class (specify path of the file in the constructor in case of loading exisitng presentation).
  • Obtain the slide’s reference by specifying it’s index.
  • Add a chart with default data along with the type ChartType.ClusteredColumn.
  • Clear the default series and categories.
  • Access the chart data workbook in a IChartDataWorkbook object.
  • Add new series and categories of the chart to the workbook.
  • Add new chart data to the chart series.
  • Finally, save the presentation using Presentation.save(String, SaveFormat) method.

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

The following is the screenshot of the resultant column chart.

Create Column Chart in PowerPoint Java

Create Scattered Chart in PowerPoint PPT using Java

The following are the steps to create a scattered chart in the PowerPoint presentation using Java.

  • Create a new presentation or load an existing one using the Presentation class.
  • Get the reference of the slide 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.
  • Access the marker of the series using IChartSeries.getMarker() and set its properties.
  • Save the presentation using Presentation.save(String, SaveFormat) method.

The following code sample shows how to create a scattered chart in PowerPoint presentations using Java.

The following screenshot shows the resultant scattered chart.

create scattered chart in powerpoint in C#

Create Pie Chart in PowerPoint PPT using Java

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

  • Create a new presentation or load an existing one using the Presentation class.
  • Get reference of the slide by providing its index.
  • Add a chart with default data along with the type ChartType.Pie.
  • Access the chart data in a IChartDataWorkbook object.
  • Clear the default series and categories.
  • Create new series and categories.
  • Add new chart data for the chart series.
  • Add new points for charts and add custom colors for the pie chart’s sectors.
  • Set labels for series and leader lines for labels.
  • Set the rotation angle for pie chart slides.
  • Save the presentation using Presentation.save(String, SaveFormat) method.

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

The following is the screenshot of the generated pie chart.

Creat Pie Chart in PowerPoint Java

Add Histogram Chart in PowerPoint PPTX using Java

The following are the steps to create a histogram chart in PowerPoint presentations using Java.

  • Create a new presentation or load existing one using Presentation class.
  • Obtain reference of the slide by providing its index.
  • Add a chart with default data along with the type ChartType.Histogram.
  • Access the chart data in IChartDataWorkbook object.
  • Clear the default series and categories.
  • Add new series and categories.
  • Save the presentation using Presentation.save(String, SaveFormat) method.

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

The following is the screenshot of the created histogram chart.

create histogram chart in powerpoint in C#

Create a Stock Chart in PowerPoint using Java

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

  • Create an instance of the Presentation class.
  • Get the reference of the slide by providing its index.
  • Add a chart with default data along with the type ChartType.OpenHighLowClose.
  • Access the chart data in IChartDataWorkbook object.
  • Clear the default series and categories.
  • Add new series and categories.
  • Add new chart data for the chart series.
  • 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 use the API without evaluation limitations.

Try Online

You can also try the free online tool for creating charts in PowerPoint presentations, which is based on Aspose.Slides.

Conclusion

In this article, you have learned how to create charts in PowerPoint presentations using Java. 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 Java using documentation. In case you would have any queries, inform us via our forum.

See Also