Load Data into Charts — Presentation API for Java
- 9 minutes to read
The Presentation API allows you to populate charts displayed on slides with data from chart data cells or values specified in code. Chart data cells are cells of an embedded workbook associated with the chart. You can also read and modify chart data in existing presentations and save chart data to external workbooks.
Chart Data Sources
Series in a standard chart use data specified by SeriesBase.setValues(value) and SeriesBase.setArguments(value) methods. Series in a ChartEx chart use data specified by DataSeriesExBase.setValues(value) and DataSeriesExBase.setArguments(value) methods.
To specify series data, pass an object of one of the following classes to the setValues(value) or setArguments(value) method:
| Class | Description |
|---|---|
| ChartDataReference | A cell, range, or union of ranges that contains chart data. |
| ChartDataExpressionReference | A reference to chart data specified by a reference expression (for example, a cell range or a defined name). |
| ChartNumericData | Numeric chart data specified in code. |
| ChartStringData | String chart data specified in code. |
| ChartHierarchicalStringData | Multi-level string chart data specified in code. |
ChartStringData and ChartHierarchicalStringData objects specify arguments only. Only treemap and sunburst series accept ChartHierarchicalStringData arguments.
Call the IChartValueData.getType() or IChartArgumentData.getType() method to get the type of series data (ChartDataType).
Bind Series to Chart Data Cells
Call the Chart.getData() or ChartEx.getData() method to access chart data cells (a ChartData object). Call the ChartData.get(cellReference) method to access a cell (ChartCellValue) at the specified address in A1 notation. If the cell does not exist, the get method creates the cell.
A new chart contains a single chart data sheet (index 0). ChartData.get methods without a sheet index parameter access cells on this sheet.
Call the following methods to specify a cell value or number format:
| Method | Description |
|---|---|
| setNumericValue(double value) | Sets the numeric value of the cell. |
| setTextValue(String value) | Sets the text value of the cell. |
| setBooleanValue(boolean value) | Sets the Boolean value of the cell. |
| setDateTimeValue(Instant value) | Sets the date value of the cell. |
| setNumberFormat(String value) | Sets the number format of the cell. |
To bind a series to cells, create a ChartDataReference object that points to a cell range and pass the reference to the setArguments(value) or setValues(value) method. To get a series name from a cell in a standard chart, pass a ChartDataReference object to the SeriesBase.setTextReference(value) method.
A data reference that you pass to the SeriesBase.setValues(value) or SeriesBase.setTextReference(value) method must point to a single cell, row, or column.
When you modify chart data cell values, the chart displays the modified values.
The following code snippet populates chart data cells with series names, months, and values, and binds two bar series to the cells:
import java.io.*;
import java.nio.file.*;
import java.time.*;
import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;
public class Main {
public static void main(String[] args) throws Exception {
try (Presentation presentation = new Presentation()) {
// Add a blank slide.
presentation.getSlides().clear();
Slide slide = new Slide(SlideLayoutType.BLANK);
presentation.getSlides().add(slide);
// Insert a chart that fills the slide.
Chart chart = new Chart();
chart.setWidth(presentation.getSlideSize().getWidth());
chart.setHeight(presentation.getSlideSize().getHeight());
slide.getShapes().add(chart);
// Populate chart data: series names in row 1, months in column A, and values in columns B and C.
ChartData data = chart.getData();
data.get("B1").setTextValue("Revenue");
data.get("C1").setTextValue("Expenses");
double[][] values = { { 120, 80 }, { 95, 70 }, { 140, 90 }, { 160, 100 } };
for (int i = 0; i < values.length; i++) {
int row = i + 2;
ChartCellValue month = data.get("A" + row);
month.setDateTimeValue(LocalDate.of(2026, i + 1, 1).atStartOfDay(ZoneOffset.UTC).toInstant());
month.setNumberFormat("MMM yyyy");
data.get("B" + row).setNumericValue(values[i][0]);
data.get("C" + row).setNumericValue(values[i][1]);
}
// Bind series names, arguments, and values to chart data cells.
for (String column : new String[] { "B", "C" }) {
BarSeries series = new BarSeries();
series.setTextReference(new ChartDataReference(column + "1"));
series.setArguments(new ChartDataReference("A2", "A5"));
series.setValues(new ChartDataReference(column + "2", column + "5"));
chart.getSeries().add(series);
}
// Display series names in the legend.
chart.setLegend(new Legend());
// Save the presentation.
Files.createDirectories(Path.of("output"));
try (OutputStream output = Files.newOutputStream(Path.of("output", "Chart.pptx"))) {
presentation.save(output);
}
}
}
}
The following screenshot illustrates the result:

Call the following methods to check the type of a cell value:
Reference Expressions
A ChartDataExpressionReference object uses a reference expression to bind series data to chart data cells. A reference expression is a formula without the equal sign (for example, Sheet1!$B$1:$B$3). In a new chart, the chart data sheet name is Sheet1.
In a loaded presentation, SeriesBase.getValues(), SeriesBase.getArguments(), and SeriesBase.getTextReference() methods return a ChartDataExpressionReference object if the reference does not point to a single cell range in chart data (for example, if the reference is a defined name).
Specify Series Data in Code
To specify series data without chart data cells, pass a ChartNumericData object to the setValues(value) method and a ChartStringData or ChartNumericData object to the setArguments(value) method.
Note
ChartNumericData and ChartStringData objects do not store date values. To display dates as arguments, populate chart data cells with date values and bind series arguments to the cells.
The following code snippet specifies arguments and values of a pie series in code:
import java.io.*;
import java.nio.file.*;
import java.util.List;
import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;
public class Main {
public static void main(String[] args) throws Exception {
try (Presentation presentation = new Presentation()) {
// Add a blank slide.
presentation.getSlides().clear();
Slide slide = new Slide(SlideLayoutType.BLANK);
presentation.getSlides().add(slide);
// Insert a chart that fills the slide.
Chart chart = new Chart();
chart.setWidth(presentation.getSlideSize().getWidth());
chart.setHeight(presentation.getSlideSize().getHeight());
slide.getShapes().add(chart);
// Create a pie series and specify data in code.
PieSeries series = new PieSeries();
series.setText("Market Share");
series.setArguments(new ChartStringData(List.of("Product A", "Product B", "Product C", "Other")));
series.setValues(new ChartNumericData(List.of(45.0, 25.0, 20.0, 10.0)));
chart.getSeries().add(series);
// Display arguments in the legend.
chart.setLegend(new Legend());
// Save the presentation.
Files.createDirectories(Path.of("output"));
try (OutputStream output = Files.newOutputStream(Path.of("output", "Chart.pptx"))) {
presentation.save(output);
}
}
}
}
The following screenshot illustrates the result:

Read Chart Data from a Presentation
Call the SeriesBase.getValues() method to get series values.
If the getValues() method returns a ChartDataReference object, pass the returned object to the ChartData.get(reference) method to get the referenced cells.
If the data type is ChartDataType.VALUES, call the IChartValueData.getNumericValues() method to get values specified in code.
The following code snippet loads a presentation and prints values of all series in standard charts:
import java.io.*;
import java.nio.file.*;
import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;
public class Main {
public static void main(String[] args) throws Exception {
try (InputStream input = Files.newInputStream(Path.of("Document.pptx"));
Presentation presentation = new Presentation(input)) {
for (Slide slide : presentation.getSlides()) {
for (ShapeBase shape : slide.getShapes()) {
if (!(shape instanceof Chart chart))
continue;
for (SeriesBase series : chart.getSeries()) {
IChartValueData values = series.getValues();
if (values instanceof ChartDataReference reference) {
// Read values from chart data cells.
for (ChartCellValue cell : chart.getData().get(reference))
System.out.println(cell.getNumericValue());
} else if (values.getType() == ChartDataType.VALUES) {
// Read values specified in code.
values.getNumericValues().forEach(System.out::println);
}
}
}
}
}
}
}
Modify Chart Data in a Presentation
To modify chart data in a loaded presentation, call the ChartData.get(reference) method to get cells that a series refers to and specify new cell values.
The following code snippet loads a presentation, finds the first chart on the first slide, and increases values of the first series by 10 percent:
import java.io.*;
import java.nio.file.*;
import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;
public class Main {
public static void main(String[] args) throws Exception {
try (InputStream input = Files.newInputStream(Path.of("Document.pptx"));
Presentation presentation = new Presentation(input)) {
// Get the first chart on the first slide.
Chart chart = (Chart) presentation.getSlides().get(0).getShapes().stream()
.filter(shape -> shape instanceof Chart)
.findFirst().orElseThrow();
// Increase values of the first series by 10 percent.
SeriesBase series = chart.getSeries().get(0);
if (series.getValues() instanceof ChartDataReference reference) {
for (ChartCellValue cell : chart.getData().get(reference))
cell.setNumericValue(cell.getNumericValue() * 1.1);
}
// Save the presentation.
Files.createDirectories(Path.of("output"));
try (OutputStream output = Files.newOutputStream(Path.of("output", "Document.pptx"))) {
presentation.save(output);
}
}
}
}
Store Chart Data in External Workbooks
The API embeds chart data workbooks in a saved presentation. To save chart data to external storage (for example, a file system or a database), implement the IChartDataStorage interface and pass the implementation to the SaveOptions.setChartDataStorage(value) method. If the storage returns a URI, the saved presentation links the chart to the workbook at the returned URI.
A chart in a PowerPoint presentation can link to an external workbook. To load linked workbooks, implement the IChartDataProvider interface and pass the implementation to the LoadOptions.setChartDataProvider(value) method. If you do not call the setChartDataProvider(value) method, the API does not load external chart workbooks.
Both interfaces are functional interfaces. You can pass a lambda expression to the setChartDataStorage(value) or setChartDataProvider(value) method.
The following code snippet saves chart data workbooks to separate files, links charts to these files, and loads the workbooks when it opens the saved presentation:
import java.io.*;
import java.nio.channels.Channels;
import java.nio.file.*;
import java.util.List;
import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;
public class Main {
public static void main(String[] args) throws Exception {
Path outputFolder = Files.createDirectories(Path.of("output")).toAbsolutePath();
try (Presentation presentation = new Presentation()) {
// Add a blank slide with a bar chart.
presentation.getSlides().clear();
Slide slide = new Slide(SlideLayoutType.BLANK);
presentation.getSlides().add(slide);
Chart chart = new Chart();
chart.setName("Sales Chart");
chart.setWidth(600);
chart.setHeight(400);
slide.getShapes().add(chart);
BarSeries series = new BarSeries();
series.setText("Sales");
series.setArguments(new ChartStringData(List.of("Q1", "Q2", "Q3", "Q4")));
series.setValues(new ChartNumericData(List.of(120.0, 150.0, 170.0, 210.0)));
chart.getSeries().add(series);
// Save each chart data workbook to a file and link the chart to the file.
SaveOptions saveOptions = new SaveOptions();
saveOptions.setChartDataStorage((context, dataChannel) -> {
Path workbook = outputFolder.resolve(context.getChartName() + ".xlsx");
try (InputStream data = Channels.newInputStream(dataChannel)) {
Files.copy(data, workbook, StandardCopyOption.REPLACE_EXISTING);
}
return workbook.toUri();
});
try (OutputStream output = Files.newOutputStream(outputFolder.resolve("Document.pptx"))) {
presentation.save(output, saveOptions);
}
}
// Load linked chart data workbooks from files.
LoadOptions loadOptions = new LoadOptions();
loadOptions.setChartDataProvider(dataUri -> Files.newByteChannel(Path.of(dataUri)));
try (InputStream input = Files.newInputStream(outputFolder.resolve("Document.pptx"));
Presentation presentation = new Presentation(input, loadOptions)) {
Chart chart = (Chart) presentation.getSlides().get(0).getShapes().get(0);
System.out.println(chart.getName() + ": " + chart.getSeries().size() + " series");
}
}
}
To remove embedded chart data and links to external workbooks when the API loads a presentation, call the PresentationSecurityLoadingOptions.setRemoveEmbeddedChartData(true) method.
Refer to the following help topics for additional information: