Customize Chart Axes — Presentation API for Java
- 12 minutes to read
The Presentation API creates chart axes when you add series to a chart. You can access axes in code to modify the axis scale, labels, titles, tick marks, gridlines, and position, or hide axes.
Most charts have two primary axes. The argument axis (X-axis) displays arguments, and the value axis (Y-axis) displays values. You can add secondary axes for series with a different value range. 3D line and surface charts, and 3D area and 3D bar charts with standard grouping, also have a series (depth) axis that displays series names. Pie and doughnut charts have no axes.
Access Axes in a Standard Chart
A standard chart (Chart) creates axes when you add the first series that requires axes. Call the following methods to access chart axes:
| Method | Description |
|---|---|
| getArgumentAxis() | Returns the primary argument axis. |
| getValueAxis() | Returns the primary value axis. |
| getSeriesAxis() | Returns the series (depth) axis of a 3D chart. |
| getSecondaryArgumentAxis() | Returns the secondary argument axis. |
| getSecondaryValueAxis() | Returns the secondary value axis. |
The first series in the chart determines axis types:
| Chart Type | Argument Axis | Value Axis | Series Axis |
|---|---|---|---|
| Area, bar, line, radar, stock | CategoryAxis or DateAxis | ValueAxis | – |
| 3D area and 3D bar charts with standard grouping, 3D line, surface, 3D surface | CategoryAxis or DateAxis | ValueAxis | SeriesAxis |
| Scatter, bubble | ValueAxis | ValueAxis | – |
| Pie, doughnut, 3D pie, bar of pie, pie of pie | – | – | – |
3D area and 3D bar charts with other grouping types have no series axis. Secondary axes do not include a series axis.
getArgumentAxis() and getSecondaryArgumentAxis() methods return an Axis object. Cast this object to the CategoryAxis, DateAxis, or ValueAxis class to call methods specific to the axis type.
Assign Axes
To replace an axis, create an axis object and pass it to the Chart.setArgumentAxis(value), Chart.setValueAxis(value), or another Chart axis setter. If you assign an axis before you add series, the chart applies the axis when you add a compatible series.
The axis type must be compatible with the series type. If you add a bar series to a chart with a value axis as the argument axis, the API throws an InvalidOperationException. The API throws the same exception if you assign a category axis to a scatter chart.
Tip
To hide an axis, call the AxisBase.setVisible(false) method.
Customize Category and Value Axes
The following code snippet creates a column chart, specifies the value axis range and number format, adds axis titles, enlarges axis labels, and displays dashed major gridlines:
import java.io.*;
import java.nio.file.*;
import java.util.List;
import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;
import com.devexpress.system.drawing.*;
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);
// Add a column series. The chart creates a category axis and a value axis.
BarSeries series = new BarSeries();
series.setArguments(new ChartStringData(List.of("Q1", "Q2", "Q3", "Q4")));
series.setValues(new ChartNumericData(List.of(42000.0, 51500.0, 47800.0, 63200.0)));
chart.getSeries().add(series);
chart.setLegend(null);
// Enlarge argument axis labels and add an axis title.
Axis argumentAxis = chart.getArgumentAxis();
TextProperties labelText = new TextProperties();
labelText.setFontSize(20f);
argumentAxis.setLabelTextProperties(labelText);
argumentAxis.setTitle(new ChartTitleOptions("Quarter"));
// Specify the value axis range and the interval between major tick marks.
ValueAxis valueAxis = chart.getValueAxis();
AxisScaling scaling = new AxisScaling();
scaling.setMin(0.0);
scaling.setMax(70000.0);
valueAxis.setScaling(scaling);
valueAxis.setMajorUnit(10000);
// Display values as currency and add a title.
NumberFormatOptions numberFormat = new NumberFormatOptions();
numberFormat.setFormatCode("$#,##0");
valueAxis.setNumberFormat(numberFormat);
valueAxis.setLabelTextProperties(labelText);
valueAxis.setTitle(new ChartTitleOptions("Revenue"));
// Display dashed major gridlines.
OutlineStyle gridlineStyle = new OutlineStyle();
gridlineStyle.setFill(new SolidFill(Color.getGray()));
gridlineStyle.setDashType(LineDashType.DASH);
ChartLineOptions gridlines = new ChartLineOptions();
gridlines.setOutlineStyle(gridlineStyle);
valueAxis.setMajorGridlines(gridlines);
// 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:

Specify the Axis Scale
To specify the axis scale, create an AxisScaling object and pass it to the Axis.setScaling(value) method. Use the following methods to configure the scale:
| Method | Description |
|---|---|
| setMin(@Nullable Double value) | Sets the minimum axis value. |
| setMax(@Nullable Double value) | Sets the maximum axis value. |
| setLogScale(boolean value) | Sets whether the axis uses a logarithmic scale. |
| setLogBase(double value) | Sets the logarithm base of a logarithmic axis scale. |
| setOrientation(AxisOrientationType value) | Sets the direction of axis values. |
Note
If you do not specify minimum and maximum values, the chart calculates them automatically.
The following code snippet applies a logarithmic scale with base 10 to the value axis:
AxisScaling scaling = new AxisScaling();
scaling.setLogScale(true);
scaling.setLogBase(10);
chart.getValueAxis().setScaling(scaling);
Use the following methods to specify intervals between tick marks and display units on a value axis:
| Method | Description |
|---|---|
| setMajorUnit(double value) | Sets the interval between major tick marks. |
| setMinorUnit(double value) | Sets the interval between minor tick marks. |
| setDisplayUnit(DisplayUnitOptions value) | Sets display unit settings for axis labels. |
Date Axes
If the first series gets arguments from chart data cells that contain dates, the chart creates a DateAxis object as the argument axis. To assign a date to a chart data cell, call the ChartCellValue.setDateTimeValue(value) method.
Use the following methods to specify time intervals on a date axis:
| Method | Description |
|---|---|
| setBaseTimeUnit(AxisTimeUnitType value) | Sets the base time unit of the date axis. |
| setMajorUnit(double value) | Sets the interval between major tick marks. |
| setMajorTimeUnit(AxisTimeUnitType value) | Sets the time unit of the interval between major tick marks. |
| setMinorUnit(double value) | Sets the interval between minor tick marks. |
| setMinorTimeUnit(AxisTimeUnitType value) | Sets the time unit of the interval between minor tick marks. |
Customize Axis Labels
Use the following methods to customize axis labels:
| Method | Description |
|---|---|
| setLabelTextProperties(TextProperties value) | Sets text formatting settings for axis labels. |
| setNumberFormat(NumberFormatOptions value) | Sets number format settings for axis labels. |
| setTickLabelPosition(AxisTickLabelPositionType value) | Sets the position of tick labels relative to the axis. |
| AxisBase.setFill(value) | Sets fill settings of the chart element. |
| setLabelAlignment(AxisLabelAlignmentType value) | Sets the horizontal alignment of axis labels. |
| setLabelOffset(int value) | Sets the distance between axis labels and the axis. |
| setTickLabelSkip(int value) | Sets the interval between displayed tick labels. |
To display labels in a custom number format, pass a NumberFormatOptions object with a format code (NumberFormatOptions.setFormatCode(value)) to the setNumberFormat(value) method. For example, the $#,##0 format code displays values as currency without decimal places:

To display labels in the number format of source data cells, call the NumberFormatOptions.setIsSourceLinked(true) method.
Add Axis Titles
To add a title to an axis, pass a ChartTitleOptions object to the Axis.setTitle(value) method. Use one of the following constructors to create the title:
ChartTitleOptions(text)creates a title with the specified text.ChartTitleOptions(textArea)creates a title with custom text. Specify text formatting settings in the TextArea object.ChartTitleOptions(reference, textProperties)creates a title that displays text from a chart data cell and applies the specified text formatting settings.
The following screenshot illustrates a chart with the Quarter argument axis title and the Revenue value axis title:

Tip
To remove an axis title, call the Axis.setTitle(null) method.
Customize Tick Marks and Gridlines
Use the following methods to customize tick marks and gridlines:
| Method | Description |
|---|---|
| setMajorTickMark(AxisTickMarkType value) | Sets the position of major tick marks. |
| setMinorTickMark(AxisTickMarkType value) | Sets the position of minor tick marks. |
| setTickMarkSkip(int value) | Sets the interval between displayed tick marks. |
| setMajorGridlines(ChartLineOptions value) | Sets line settings for major gridlines. |
| setMinorGridlines(ChartLineOptions value) | Sets line settings for minor gridlines. |
To hide gridlines, call the setMajorGridlines(null) or setMinorGridlines(null) method.
The following code snippet displays major tick marks that cross the category axis and displays every second axis label:
CategoryAxis categoryAxis = (CategoryAxis) chart.getArgumentAxis();
categoryAxis.setMajorTickMark(AxisTickMarkType.CROSS);
categoryAxis.setTickLabelSkip(2);
Specify the Axis Position
Use the following methods to specify the axis position:
| Method | Description |
|---|---|
| setPosition(AxisPositionType value) | Sets the axis position in the chart. |
| setCrossType(AxisCrossType value) | Sets the point at which the axis crosses the perpendicular axis. |
| setCrossesAt(double value) | Sets the value on the perpendicular axis at which the axis crosses it. |
| setCrossPositionType(AxisCrossPositionType value) | Sets the position at which the value axis crosses the category axis. |
The following code snippet moves the category axis so that it crosses the value axis at 20000:
Axis argumentAxis = chart.getArgumentAxis();
argumentAxis.setCrossType(AxisCrossType.CUSTOM);
argumentAxis.setCrossesAt(20000);
Customize the Axis Line
To customize the axis line, pass an OutlineStyle object to the AxisBase.setOutlineStyle(value) method.
The following code snippet displays the category axis as a thick orange line and hides the value axis:
OutlineStyle axisLine = new OutlineStyle();
axisLine.setFill(new SolidFill(Color.getOrange()));
axisLine.setWidth(3);
chart.getArgumentAxis().setOutlineStyle(axisLine);
chart.getValueAxis().setVisible(false);
Add Secondary Axes
If series value ranges differ significantly, display a series on secondary axes. To move a series to secondary axes, call the setAxisGroup(ChartAxisGroupType.SECONDARY) method of the series. The chart displays the series in a separate chart view and creates secondary axes for this view.
Call one of the following methods to specify the axis group of a series:
- AreaSeries.setAxisGroup(value)
- BarSeries.setAxisGroup(value)
- LineSeries.setAxisGroup(value)
- RadarSeries.setAxisGroup(value)
- ScatterSeries.setAxisGroup(value)
- StockSeries.setAxisGroup(value)
The following code snippet displays the second line series on secondary axes and moves the secondary value axis to the right side of the plot area:
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");
// Add a revenue series to the primary axes.
LineSeries revenue = new LineSeries();
revenue.setText("Revenue");
revenue.setArguments(new ChartStringData(months));
revenue.setValues(new ChartNumericData(List.of(48000.0, 52000.0, 61000.0, 58000.0, 67000.0, 72000.0)));
chart.getSeries().add(revenue);
// Add an order count series to the secondary axes.
LineSeries orders = new LineSeries();
orders.setText("Orders");
orders.setArguments(new ChartStringData(months));
orders.setValues(new ChartNumericData(List.of(310.0, 290.0, 405.0, 380.0, 460.0, 515.0)));
orders.setAxisGroup(ChartAxisGroupType.SECONDARY);
chart.getSeries().add(orders);
// 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);
// Hide secondary value axis gridlines.
secondaryValueAxis.setMajorGridlines(null);
// Enlarge axis labels.
TextProperties labelText = new TextProperties();
labelText.setFontSize(16f);
chart.getArgumentAxis().setLabelTextProperties(labelText);
chart.getValueAxis().setLabelTextProperties(labelText);
secondaryValueAxis.setLabelTextProperties(labelText);
// Add titles to value axes.
chart.getValueAxis().setTitle(new ChartTitleOptions("Revenue ($)"));
secondaryValueAxis.setTitle(new ChartTitleOptions("Orders"));
// 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: Create Combo Charts — Presentation API for Java.
Display a Multilevel Category Axis
A category axis displays multilevel labels if series arguments refer to multiple adjacent columns of chart data cells. The first column contains top-level categories. To display labels without a hierarchy, call the CategoryAxis.setNoMultilevelLabels(true) method.
The following code snippet displays half-years grouped by year on the category axis:
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 {
String[] halves = { "H1", "H2", "H1", "H2" };
double[] sales = { 120, 145, 160, 190 };
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);
// Column A contains years, column B contains half-years, and column C contains values.
ChartData data = chart.getData();
data.get(0, "A1").setTextValue("2025");
data.get(0, "A3").setTextValue("2026");
for (int i = 0; i < sales.length; i++) {
data.get(0, "B" + (i + 1)).setTextValue(halves[i]);
data.get(0, "C" + (i + 1)).setNumericValue(sales[i]);
}
// Pass the A1:B4 range to series arguments to display two label levels.
BarSeries series = new BarSeries();
series.setArguments(new ChartDataReference(0, "A1", "B4"));
series.setValues(new ChartDataReference(0, "C1", "C4"));
chart.getSeries().add(series);
chart.setLegend(null);
// Enlarge category axis labels.
TextProperties labelText = new TextProperties();
labelText.setFontSize(20f);
chart.getArgumentAxis().setLabelTextProperties(labelText);
// 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:

Axes in Chart Types Introduced in Microsoft Excel 2016
A chart of a type introduced in Microsoft Excel 2016 (ChartEx) creates axes when you add the first series. Call the following methods to access chart axes:
| Method | Description |
|---|---|
| getArgumentAxis() | Returns the category axis. |
| getValueAxis() | Returns the primary value axis. |
| getSecondaryValueAxis() | Returns the secondary value axis. |
The chart type determines available axes:
| Chart Type | Category Axis | Value Axis | Secondary Value Axis |
|---|---|---|---|
| Box and whisker, histogram, waterfall | CategoryAxisEx | ValueAxisEx | – |
| Pareto | CategoryAxisEx | ValueAxisEx | ValueAxisEx |
| Funnel | CategoryAxisEx | – | – |
| Map, sunburst, treemap | – | – | – |
CategoryAxisEx and ValueAxisEx classes derive from the AxisEx class. To customize labels, tick marks, gridlines, and visibility, call AxisBase methods in the same way as you do in standard charts. Use the following AxisEx methods to specify other axis settings:
| Method | Description |
|---|---|
| setTitle(ChartTitleOptionsEx value) | Sets axis title settings. |
| setMajorUnit(double value) | Sets the interval between major tick marks. |
| setMinorUnit(double value) | Sets the interval between minor tick marks. |
| setDisplayUnit(DisplayUnitOptionsEx value) | Sets display unit settings for axis labels. |
The following code snippet creates a waterfall chart, displays value axis labels in thousands, specifies the interval between major tick marks, and adds a value axis title:
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 {
String[] months = { "Start", "Jan", "Feb", "Mar", "Apr" };
double[] amounts = { 10000, 12000, -5000, 8000, 6000 };
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.
ChartEx chart = new ChartEx();
chart.setWidth(presentation.getSlideSize().getWidth());
chart.setHeight(presentation.getSlideSize().getHeight());
slide.getShapes().add(chart);
// Add months and amounts to chart data cells.
ChartData data = chart.getData();
for (int i = 0; i < months.length; i++) {
data.get(0, "A" + (i + 1)).setTextValue(months[i]);
data.get(0, "B" + (i + 1)).setNumericValue(amounts[i]);
}
// Add a waterfall series. The chart creates a category axis and a value axis.
WaterfallSeries series = new WaterfallSeries();
series.setArguments(new ChartDataReference(0, "A1", "A5"));
series.setValues(new ChartDataReference(0, "B1", "B5"));
chart.getSeries().add(series);
// Display value axis labels in thousands and add an axis title.
ValueAxisEx valueAxis = chart.getValueAxis();
valueAxis.setMajorUnit(5000);
NumberFormatOptions numberFormat = new NumberFormatOptions();
numberFormat.setFormatCode("$#,##0,\"K\"");
valueAxis.setNumberFormat(numberFormat);
valueAxis.setTitle(new ChartTitleOptionsEx("Cash Flow"));
// Save the presentation.
Files.createDirectories(Path.of("output"));
try (OutputStream output = Files.newOutputStream(Path.of("output", "Chart.pptx"))) {
presentation.save(output);
}
}
}
}
Refer to the following help topic for additional information: Create Waterfall, Funnel, Treemap, and Other Office 2016 Charts.