Create Combo Charts — Presentation API for Java
- 7 minutes to read
The Presentation API allows you to combine series of different chart types in a single standard chart (a combo chart). For example, a combo chart can display sales as columns and a sales target as a line. To display series with different value ranges in one chart, plot a series on secondary axes.
A combo chart is a Chart object that contains series of multiple types.
Create a Combo Chart
Follow the steps below to add a combo chart to a slide:
- Create a
Chartobject, specify the chart position and size, and add the chart to the SlideBase.getShapes() collection. - Create series of different types (for example, BarSeries, AreaSeries, and LineSeries objects) and specify series data.
- Add the series to the Chart.getSeries() collection.
The following code snippet populates chart data cells and creates a combo chart that displays sales as columns, last year’s sales as an area, and a sales target as a line:
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 (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 cells.
ChartData data = chart.getData();
data.get("B1").setTextValue("This Year");
data.get("C1").setTextValue("Last Year");
data.get("D1").setTextValue("Target");
String[] quarters = { "Q1", "Q2", "Q3", "Q4" };
double[][] values = { { 26, 36, 30 }, { 34, 40, 35 }, { 45, 42, 40 }, { 52, 47, 45 } };
for (int i = 0; i < quarters.length; i++) {
data.get("A" + (i + 2)).setTextValue(quarters[i]);
data.get("B" + (i + 2)).setNumericValue(values[i][0]);
data.get("C" + (i + 2)).setNumericValue(values[i][1]);
data.get("D" + (i + 2)).setNumericValue(values[i][2]);
}
// Add a bar series, an area series, and a line series.
SeriesBase[] series = { new BarSeries(), new AreaSeries(), new LineSeries() };
String[] columns = { "B", "C", "D" };
for (int i = 0; i < series.length; i++) {
series[i].setTextReference(new ChartDataReference(columns[i] + "1"));
series[i].setArguments(new ChartDataReference("A2", "A5"));
series[i].setValues(new ChartDataReference(columns[i] + "2", columns[i] + "5"));
chart.getSeries().add(series[i]);
}
// 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:

Tip
The chart creates axes based on the first chart view in an axis group that uses axes. If the first view is an area view, the value axis crosses the category axis at tick marks, and the chart displays only half of the first and last columns.
To display whole columns, add bar series to the chart first or call the ValueAxis.setCrossPositionType(AxisCrossPositionType.BETWEEN_TICK_MARKS) method for the value axis (Chart.getValueAxis()).
Configure Chart Views in a Combo Chart
A standard chart displays series in chart views. When you add the first series of a chart type to an axis group, the chart creates a view for this chart type and axis group. When you remove the last series in the view, the chart removes the view. A view stores settings that apply to all series in the view (for example, the gap width between columns).
Call the Chart.getViews() method to access chart views. Call the ChartViewBase.getChartType() and ChartViewBase.getAxisGroup() methods to identify a view. To configure a view, cast the view to a view class (for example, BarChartView).
The following code snippet specifies the gap width between columns in a combo chart:
for (ChartViewBase view : chart.getViews()) {
if (view instanceof BarChartView barView)
barView.setGapWidth(60);
}
Refer to the following help topic for additional information: Create Standard Charts — Presentation API for Java.
Plot a Series on Secondary Axes
If series value ranges differ significantly (for example, revenue and profit margin), display a series on secondary axes. Call the setAxisGroup(ChartAxisGroupType.SECONDARY) method of the series before you add the series to the chart. The chart displays the series in a separate view and creates secondary axes (Chart.getSecondaryArgumentAxis() and Chart.getSecondaryValueAxis()).
Call one of the following methods to specify the axis group of a series:
- AreaSeries.setAxisGroup(value)
- BarSeries.setAxisGroup(value)
- DoughnutSeries.setAxisGroup(value)
- LineSeries.setAxisGroup(value)
- PieSeries.setAxisGroup(value)
- RadarSeries.setAxisGroup(value)
- ScatterSeries.setAxisGroup(value)
- StockSeries.setAxisGroup(value)
The following code snippet displays monthly revenue as columns on the primary axes and profit margin as a line on the secondary axes, moves the secondary value axis to the right side of the plot area, and formats value axis labels as currency and percentages:
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);
List<String> months = List.of("Jan", "Feb", "Mar", "Apr", "May", "Jun");
// Display revenue as columns on the primary axes.
BarSeries revenue = new BarSeries();
revenue.setText("Revenue");
revenue.setArguments(new ChartStringData(months));
revenue.setValues(new ChartNumericData(List.of(42000.0, 48500.0, 51200.0, 47800.0, 57800.0, 63100.0)));
chart.getSeries().add(revenue);
// Display profit margin as a line on the secondary axes.
LineSeries margin = new LineSeries();
margin.setText("Profit Margin");
margin.setArguments(new ChartStringData(months));
margin.setValues(new ChartNumericData(List.of(0.12, 0.15, 0.14, 0.11, 0.17, 0.19)));
margin.setAxisGroup(ChartAxisGroupType.SECONDARY);
chart.getSeries().add(margin);
// Configure the view that displays columns.
for (ChartViewBase view : chart.getViews()) {
if (view instanceof BarChartView barView)
barView.setGapWidth(60);
}
// Hide the secondary argument axis and move the secondary value axis to the right side.
chart.getSecondaryArgumentAxis().setVisible(false);
ValueAxis secondaryValueAxis = chart.getSecondaryValueAxis();
secondaryValueAxis.setCrossType(AxisCrossType.MAX);
secondaryValueAxis.setMajorGridlines(null);
// Format value axis labels.
NumberFormatOptions currency = new NumberFormatOptions();
currency.setFormatCode("$#,##0");
chart.getValueAxis().setNumberFormat(currency);
NumberFormatOptions percent = new NumberFormatOptions();
percent.setFormatCode("0%");
secondaryValueAxis.setNumberFormat(percent);
// Display the legend below the plot area.
chart.getLegend().setPosition(LegendPositionType.BOTTOM);
// 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:

Refer to the following help topic for additional information: Customize Chart Axes — Presentation API for Java.
Display a Series as Another Chart Type
To display an existing chart series as another chart type, call the SeriesBase.convertTo(chartType) method. The convertTo method creates a series of the specified chart type with the same data, settings, and axis group. Replace the source series with the converted series in the Chart.getSeries() collection.
The following code snippet converts the second series of a bar chart (Orders) to a line series, displays the line series on secondary axes, and moves the secondary value axis to the right side of the plot area:
LineSeries lineSeries = (LineSeries) chart.getSeries().get(1).convertTo(ChartType.LINE);
lineSeries.setAxisGroup(ChartAxisGroupType.SECONDARY);
chart.getSeries().set(1, lineSeries);
// Hide the secondary argument axis and move the secondary value axis to the right side.
chart.getSecondaryArgumentAxis().setVisible(false);
chart.getSecondaryValueAxis().setCrossType(AxisCrossType.MAX);
chart.getSecondaryValueAxis().setMajorGridlines(null);
The following screenshot illustrates the result:

Compatible Series Types
Series in the same axis group must use the same axes:
| Axes | Series Classes |
|---|---|
| A category axis and a value axis | AreaSeries, BarSeries, LineSeries, RadarSeries, StockSeries, Area3DSeries with stacked or 100% stacked grouping (Area3DChartView.setGrouping(value) method), Bar3DSeries with clustered, stacked, or 100% stacked grouping (Bar3DChartView.setBarGrouping(value) method) |
| Two value axes (X and Y) | ScatterSeries, BubbleSeries |
| A category axis, a value axis, and a series axis | Line3DSeries, SurfaceSeries, Surface3DSeries, Area3DSeries with standard grouping (ChartGrouping.STANDARD), Bar3DSeries with standard grouping (BarChartGrouping.STANDARD) |
If a series is not compatible with other chart series, add and set methods of the Chart.getSeries() collection do not modify the collection and throw an InvalidOperationException. The following table lists incompatible series and exception messages:
| Incompatible Series | Exception Message |
|---|---|
| Series in the same axis group use different axes (for example, a bar series and a scatter series on the primary axes). | “Views with incompatible axis types cannot share an axis group.” |
| A series on the secondary axes uses a series axis (for example, a 3D bar series converted from a bar series on the secondary axes). | “The secondary axis group cannot contain series that require three axes.” |
| The chart contains series that use a series axis and scatter or bubble series. | “Series that require three axes cannot share an axis group with XY series (Scatter or Bubble).” |
| The chart contains a Pie3DSeries object and area, bar, line, radar, stock, scatter, or bubble series. | “3D Pie series cannot share an axis group with series that require two axes.” |
Warning
Do not combine 3D series with series of other chart types. Microsoft PowerPoint cannot display charts that combine 3D series with other series types.