PNG JPG BMP TIFF PPTX
Aspose.Slides  for Java

PPTX Formats Charts in Java

Native and high performance PPTX document charts using server-side Aspose.Slides for Java APIs, without the use of any software like Microsoft or Adobe PDF.

Create PPTX File Charts Using Java

In order to create PPTX file charts, we’ll use

Aspose.Slides for Java

API which is a feature-rich, powerful and easy to use charting API for Java platform. You can download its latest version directly from

Maven

and install it within your Maven-based project by adding the following configurations to the pom.xml.

Repository


<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://releases.aspose.com/java/repo/</url>
</repository>

Dependency


<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-slides</artifactId>
    <version>version of aspose-slides API</version>
    <classifier>jdk17</classifier>
</dependency>

How to Create PPTX Files Charts in Java

A basic document charting with Aspose.Slides for Java APIs can be done with just few lines of code.

  1. Instantiate Presentation class object.

  2. Get first slide.

  3. Add chart with default data.

  4. Set chart Title.

  5. Set first series to Show Values.

  6. Set the index of chart data sheet.

  7. Get the chart data worksheet.

  8. Delete default generated series and categories.

  9. Adding new series and categories.

  10. Take first chart series.

  11. Populate series data.

  12. Set fill color for series.

  13. create custom labels for each of categories for new series.

  14. Save presentation with chart.

System Requirements

Aspose.Slides for Java supports on all major platforms and Operating Systems. Please make sure that you have the following prerequisites.

  • Microsoft Windows or a compatible OS with Java Runtime Environment for JSP/JSF Application and Desktop Applications.
  • Get latest version of Aspose.Slides for Java directly from Maven .
 

Create PPTX Files Chart - Java

//Instantiate Presentation class 
Presentation pres = new Presentation();

//Access first slide
ISlide sld = pres.getSlides().get_Item(0);

// Add chart with default data
IChart chart = sld.getShapes().addChart(ChartType.ClusteredColumn, 0, 0, 500, 500);

//Setting chart Title
//chart.getChartTitle().TextFrameForOverriding.Text = "Title";
chart.getChartTitle().addTextFrameForOverriding("Title");
chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat().setCenterText(NullableBool.True);
chart.getChartTitle().setHeight(20);
chart.hasTitle(true);

//Set first series to Show Values
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true);

//Setting the index of chart data sheet
int defaultWorksheetIndex = 0;

//Getting the chart data worksheet
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();

//Delete default generated series and categories
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
int s = chart.getChartData().getSeries().size();
s = chart.getChartData().getCategories().size();

//Adding new series
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.getType());
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.getType());

//Adding new categories
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1"));
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2"));
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3"));

//Take first chart series
IChartSeries series = chart.getChartData().getSeries().get_Item(0);

//Now populating series data

series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 20));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 50));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 30));

//Setting fill color for series
series.getFormat().getFill().setFillType(FillType.Solid);
series.getFormat().getFill().getSolidFillColor().setColor(java.awt.Color.RED);

//Take second chart series
series = chart.getChartData().getSeries().get_Item(1);

//Now populating series data
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 2, 30));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 2, 10));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 2, 60));

//Setting fill color for series
series.getFormat().getFill().setFillType(FillType.Solid);
series.getFormat().getFill().getSolidFillColor().setColor(java.awt.Color.GREEN);

//create custom labels for each of categories for new series

//first label will be show Category name
IDataLabel lbl = series.getDataPoints().get_Item(0).getLabel();
lbl.getDataLabelFormat().setShowCategoryName(true);

lbl = series.getDataPoints().get_Item(1).getLabel();
lbl.getDataLabelFormat().setShowSeriesName(true);

//Show value for third label
lbl = series.getDataPoints().get_Item(2).getLabel();
lbl.getDataLabelFormat().setShowValue(true);
lbl.getDataLabelFormat().setShowSeriesName(true);
lbl.getDataLabelFormat().setSeparator("/");

//Save presentation with chart
pres.save("AsposeChart.pptx",SaveFormat.Pptx);  

    
 
  • About Aspose.Slides for Java API

    Generate PPTX documents charts right now by visiting our

    Live Demos website

    . The live demo has the following benefits

    Online PPTX Chart Creation Live Demos

    Generate PPTX documents charts right now by visiting our Live Demos website . The live demo has the following benefits

      No need to download Aspose API.
      No need to write any code.
      Just upload your PPTX files.
      Chart will be created instantly.

    PPTX What is PPTX File Format?

    Files with PPTX extension are presentation files created with popular Microsoft PowerPoint application. Unlike the previous version of presentation file format PPT which was binary, the PPTX format is based on the Microsoft PowerPoint open XML presentation file format. A presentation file is a collection of slides where each slide can comprise of text, images, formatting, animations, and other media. These slides are presented to audience in the form of slideshows with custom presentation settings.

    Read More

    Other Supported Charting Formats

    Using Java, one can easily deal charing with different formats including.

    PPT (Microsoft PowerPoint 97-2003)