Customize Chart Data Labels — Presentation API for Java
- 11 minutes to read
The Presentation API allows you to display data labels in charts. Data labels display values, category names, series names, percentages, bubble sizes, or text from chart data cells next to data points. You can configure data labels for an entire chart view, individual series, or individual data points.
Display Data Labels in a Standard Chart
A standard chart (Chart) does not display data labels until you enable label content (for example, until you call the setShowValue(true) method). Call the getDataLabels() method of a series or a chart view to access data label settings:
| Series Type | Series Method | Chart View Method |
|---|---|---|
| Area, 3D area | AreaSeries.getDataLabels() | – |
| Bar | getDataLabels() | getDataLabels() |
| 3D bar | getDataLabels() | – |
| Bubble | getDataLabels() | getDataLabels() |
| Doughnut | getDataLabels() | getDataLabels() |
| Line | getDataLabels() | getDataLabels() |
| 3D line | getDataLabels() | – |
| Pie | getDataLabels() | getDataLabels() |
| 3D pie | Pie3DSeries.getDataLabels() | getDataLabels() |
| Pie of pie, bar of pie | ChartOfPieSeries.getDataLabels() | getDataLabels() |
| Radar | getDataLabels() | – |
| Scatter | getDataLabels() | getDataLabels() |
| Stock | getDataLabels() | getDataLabels() |
View-level settings apply to all series in the view. Series-level settings take precedence over view-level settings. To access a chart view, call the Chart.getViews() method and cast the view to the view class (for example, BarChartView).
The following code snippet displays values above columns of all series in a bar chart view and displays series names and values inside columns of the second series:
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);
// Add two column series.
List<String> quarters = List.of("Q1", "Q2", "Q3", "Q4");
BarSeries sales2025 = new BarSeries();
sales2025.setText("2025");
sales2025.setArguments(new ChartStringData(quarters));
sales2025.setValues(new ChartNumericData(List.of(42.0, 51.5, 47.8, 63.2)));
chart.getSeries().add(sales2025);
BarSeries sales2026 = new BarSeries();
sales2026.setText("2026");
sales2026.setArguments(new ChartStringData(quarters));
sales2026.setValues(new ChartNumericData(List.of(48.3, 55.1, 58.9, 70.4)));
chart.getSeries().add(sales2026);
// Display values above columns of all series in the view.
BarChartView view = (BarChartView) chart.getViews().get(0);
IBarDataLabels viewLabels = view.getDataLabels();
viewLabels.setShowValue(true);
viewLabels.setLabelPosition(BarDataLabelPosition.OUTSIDE_END);
TextProperties labelText = new TextProperties();
labelText.setFontSize(16f);
viewLabels.setTextProperties(labelText);
// Display series names in data labels of the second series.
IBarDataLabels seriesLabels = sales2026.getDataLabels();
seriesLabels.setShowValue(true);
seriesLabels.setShowSeriesText(true);
seriesLabels.setSeparator("\n");
seriesLabels.setLabelPosition(BarDataLabelPosition.INSIDE_END);
seriesLabels.setTextProperties(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:

Specify Data Label Content
Call the following methods to specify data label content:
| Method | Description |
|---|---|
| setShowValue(boolean value) | Sets whether to display data point values in data labels. |
| setShowCategoryName(boolean value) | Sets whether to display category names in data labels. |
| setShowSeriesText(boolean value) | Sets whether to display the series name in data labels. |
| setShowLegendKey(boolean value) | Sets whether to display legend keys in data labels. |
| setShowDataLabelRange(boolean value) | Sets whether to display text from a cell range in data labels. |
| setShowPercent(boolean value) | Sets whether data labels display percentage values. |
| setShowPercent(boolean value) | Sets whether data labels display percentage values. |
| setShowBubbleSize(boolean value) | Sets whether to display bubble sizes in data labels. |
| setSeparator(String value) | Sets the separator between parts of data label text. |
If a data label displays multiple parts, the label uses a comma followed by a space as the separator. To display each part on a separate line, call the setSeparator("\n") method.
The following code snippet creates a pie chart and displays category names and percentages on separate lines outside pie slices:
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);
// Add a pie series and paint each slice in a different color.
PieSeries series = new PieSeries();
series.setArguments(new ChartStringData(List.of("Online", "Retail", "Wholesale", "Partners")));
series.setValues(new ChartNumericData(List.of(4200.0, 3100.0, 1800.0, 900.0)));
chart.getSeries().add(series);
((PieChartView) chart.getViews().get(0)).setVaryColors(true);
chart.setLegend(null);
// Display category names and percentages on separate lines outside slices.
IPieDataLabels labels = series.getDataLabels();
labels.setShowCategoryName(true);
labels.setShowPercent(true);
labels.setSeparator("\n");
labels.setLabelPosition(PieDataLabelPosition.OUTSIDE_END);
TextProperties labelText = new TextProperties();
labelText.setFontSize(18f);
labels.setTextProperties(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:

To connect data labels to data points with leader lines, call the IDataLabels.setShowLeaderLines(true) method. Call the IDataLabels.setLeaderLineProperties(value) method to customize leader line appearance.
Specify the Data Label Position
The setLabelPosition(value) method of a data label settings object specifies the label position relative to data points. Available positions depend on the series type:
Note
Area, 3D area, 3D bar, 3D line, doughnut, and radar series do not have a data label position setting.
The following code snippet displays data labels of a line series above data points:
ILineDataLabels labels = lineSeries.getDataLabels();
labels.setShowValue(true);
labels.setLabelPosition(LineDataLabelPosition.TOP);
Format Numbers in Data Labels
To specify the number format of values in data labels, pass a NumberFormatOptions object to the IDataLabelBase.setNumberFormat(value) method. Call the NumberFormatOptions.setFormatCode(value) method to specify the format code.
To display values in the number format of source data cells, call the NumberFormatOptions.setIsSourceLinked(true) method. In this instance, the label ignores the format code.
The following code snippet displays values with a thousands separator and two decimal places:
NumberFormatOptions numberFormat = new NumberFormatOptions();
numberFormat.setFormatCode("#,##0.00");
series.getDataLabels().setNumberFormat(numberFormat);
Customize Data Label Appearance
Call the following methods to customize data label appearance:
| Method | Description |
|---|---|
| setTextProperties(TextProperties value) | Sets text formatting settings for data labels. |
| setProperties(ChartElement value) | Sets fill, outline, and shape effect settings for data labels. |
The following code snippet displays values and legend keys in data labels, applies bold dark blue text formatting, and adds a light yellow fill and a gray outline to data labels:
IBarDataLabels labels = series.getDataLabels();
labels.setShowValue(true);
labels.setShowLegendKey(true);
// Apply bold dark blue text formatting.
TextProperties labelText = new TextProperties();
labelText.setFontSize(20f);
labelText.setBold(true);
labelText.setFill(new SolidFill(Color.getDarkBlue()));
labels.setTextProperties(labelText);
// Fill data labels with light yellow and add a gray outline.
OutlineStyle outline = new OutlineStyle();
outline.setFill(new SolidFill(Color.getGray()));
ChartElement labelProperties = new ChartElement();
labelProperties.setFill(new SolidFill(Color.getLightYellow()));
labelProperties.setOutlineStyle(outline);
labels.setProperties(labelProperties);
The following screenshot illustrates the result:

Customize Labels of Individual Data Points
The data label settings object of a series is also a map of individual data labels (Map<Integer, DataLabel>). Map keys are zero-based data point indexes. To customize the label of an individual data point, do the following:
- Create a data label object of the series type (for example, BarDataLabel for a bar series).
- Pass the created object to the
setLabel(key, value)method of the data label settings object (for example, IBarDataLabels.setLabel(key, value)).
Settings of an individual data label take precedence over series-level settings. A hidden data label does not display content, regardless of other label settings.
To remove individual data label settings, call the remove(key) method of the data label settings object.
Call the following methods to specify individual data label content:
| Method | Description |
|---|---|
| setCustomText(TextArea value) | Sets custom text of the data label. |
| setTextReference(IChartDataReference value) | Sets a chart data reference to the data label text. |
| DataLabel.setHidden(value) | Sets whether to hide the data label. |
Note
If a series contains individual data labels, PowerPoint ignores view-level label content settings for the series. Specify label content settings at the series level.
The following code snippet hides the label of the first data point and displays custom text in the label of the fourth data point:
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);
// Add a column series.
BarSeries series = new BarSeries();
series.setArguments(new ChartStringData(List.of("Jan", "Feb", "Mar", "Apr", "May")));
series.setValues(new ChartNumericData(List.of(24.0, 38.0, 45.0, 72.0, 51.0)));
chart.getSeries().add(series);
chart.setLegend(null);
// Display values above all columns.
IBarDataLabels labels = series.getDataLabels();
labels.setShowValue(true);
labels.setLabelPosition(BarDataLabelPosition.OUTSIDE_END);
TextProperties labelText = new TextProperties();
labelText.setFontSize(18f);
labels.setTextProperties(labelText);
// Hide the label of the first data point (zero-based index 0).
BarDataLabel hiddenLabel = new BarDataLabel();
hiddenLabel.setHidden(true);
labels.setLabel(0, hiddenLabel);
// Display bold custom text in the label of the fourth data point.
TextProperties highlightText = new TextProperties();
highlightText.setFontSize(18f);
highlightText.setBold(true);
BarDataLabel recordLabel = new BarDataLabel();
recordLabel.setCustomText(new TextArea("Record: 72"));
recordLabel.setTextProperties(highlightText);
labels.setLabel(3, recordLabel);
// 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:

Display Text from Chart Data Cells in Data Labels
To display text from chart data cells in series data labels, do the following:
- Pass a cell range reference to the
setDataLabelsRange(value)method (for example, BarSeries.setDataLabelsRange(value)). - Call the
setShowDataLabelRange(true)method.
Each data label displays text from the cell that has the same position in the referenced range as the data point in the series.
The following code snippet displays values and product notes from cells C1:C4 in data labels:
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[] products = { "Laptops", "Tablets", "Phones", "Monitors" };
double[] units = { 120, 85, 210, 64 };
String[] notes = { "New model", "Discontinued", "Best seller", "Clearance" };
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 arguments, column B contains values, and column C contains label text.
ChartData data = chart.getData();
for (int i = 0; i < products.length; i++) {
data.get(0, "A" + (i + 1)).setTextValue(products[i]);
data.get(0, "B" + (i + 1)).setNumericValue(units[i]);
data.get(0, "C" + (i + 1)).setTextValue(notes[i]);
}
// Add a column series.
BarSeries series = new BarSeries();
series.setArguments(new ChartDataReference(0, "A1", "A4"));
series.setValues(new ChartDataReference(0, "B1", "B4"));
chart.getSeries().add(series);
chart.setLegend(null);
// Display text from the C1:C4 cells and values in data labels.
series.setDataLabelsRange(new ChartDataReference(0, "C1", "C4"));
IBarDataLabels labels = series.getDataLabels();
labels.setShowDataLabelRange(true);
labels.setShowValue(true);
labels.setSeparator("\n");
labels.setLabelPosition(BarDataLabelPosition.OUTSIDE_END);
TextProperties labelText = new TextProperties();
labelText.setFontSize(18f);
labels.setTextProperties(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:

Data Labels in Chart Types Introduced in Microsoft Excel 2016
Chart types introduced in Microsoft Excel 2016 (ChartEx) do not have view-level data label settings. Call the getDataLabels() method of a series to access data label settings:
| Series Type | Method | Position Setting |
|---|---|---|
| Box and whisker | getDataLabels() | setLabelPosition(BoxAndWhiskerDataLabelPosition value) |
| Funnel | getDataLabels() | – |
| Histogram | getDataLabels() | setLabelPosition(HistogramDataLabelPosition value) |
| Pareto | getDataLabels() | – |
| Sunburst | getDataLabels() | – |
| Treemap | getDataLabels() | – |
| Waterfall | getDataLabels() | setLabelPosition(WaterfallDataLabelPosition value) |
The returned objects implement the IDataLabelsEx interface. Call IDataLabelExBase methods to specify label content, number format, and appearance. These objects do not have legend key, cell range, hidden state, or leader line settings.
To customize the label of an individual data point, pass a DataLabelEx object of the series type (for example, WaterfallDataLabel) to the setLabel(key, value) method.
The following code snippet creates a waterfall chart and displays values in thousands above columns:
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.
WaterfallSeries series = new WaterfallSeries();
series.setArguments(new ChartDataReference(0, "A1", "A5"));
series.setValues(new ChartDataReference(0, "B1", "B5"));
chart.getSeries().add(series);
// Display values in thousands above columns.
IWaterfallDataLabels labels = series.getDataLabels();
labels.setShowValue(true);
labels.setLabelPosition(WaterfallDataLabelPosition.OUTSIDE_END);
NumberFormatOptions numberFormat = new NumberFormatOptions();
numberFormat.setFormatCode("$#,##0,\"K\"");
labels.setNumberFormat(numberFormat);
TextProperties labelText = new TextProperties();
labelText.setFontSize(18f);
labels.setTextProperties(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:

Refer to the following help topic for additional information: Create Waterfall, Funnel, Treemap, and Other Office 2016 Charts.