PieDataLabel Class
Contains settings for a data label in a pie chart.
Declaration
public class PieDataLabel extends DataLabel
Remarks
The PieDataLabel class inherits label content and formatting settings from DataLabel and DataLabelBase classes (for example, PieDataLabel.setShowValue(value) and PieDataLabel.setCustomText(value) methods).
The setLabelPosition(PieDataLabelPosition value) method specifies the label position relative to the pie slice.
The setShowPercent(boolean value) method specifies whether the data label displays the percentage value.
Refer to the following help topic for additional information: Customize Chart Data Labels — Presentation API for Java.
Example
Create a Pie Chart with an Exploded Slice
The following code snippet creates a pie chart, pulls the first slice out of the pie, displays category names and percentages in data labels, and applies bold text formatting to the first data label:
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.
PieSeries series = new PieSeries();
series.setText("Budget");
series.setArguments(new ChartStringData(List.of("Salaries", "Marketing", "Rent", "Equipment", "Travel")));
series.setValues(new ChartNumericData(List.of(48.0, 20.0, 15.0, 10.0, 7.0)));
chart.getSeries().add(series);
// Pull the first slice out of the pie.
DataPoint salaries = new DataPoint();
salaries.setExplosion(15);
series.getCustomDataPoints().put(0, salaries);
// Color each slice differently.
PieChartView view = (PieChartView) chart.getViews().get(0);
view.setVaryColors(true);
// Display category names and percentages outside slices.
IPieDataLabels dataLabels = series.getDataLabels();
dataLabels.setShowCategoryName(true);
dataLabels.setShowPercent(true);
dataLabels.setLabelPosition(PieDataLabelPosition.OUTSIDE_END);
// Apply bold text formatting to the data label of the first slice.
TextProperties boldText = new TextProperties();
boldText.setBold(true);
PieDataLabel salariesLabel = new PieDataLabel();
salariesLabel.setShowCategoryName(true);
salariesLabel.setShowPercent(true);
salariesLabel.setLabelPosition(PieDataLabelPosition.OUTSIDE_END);
salariesLabel.setTextProperties(boldText);
dataLabels.setLabel(0, salariesLabel);
// 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:

Inherited Members
Inheritance
PieDataLabel()
Initializes a new instance of the PieDataLabel class.
Declaration
public PieDataLabel()
Methods
deepClone() Method
Returns a deep copy of this PieDataLabel instance.
Declaration
public PieDataLabel deepClone()
Returns
| Type | Description |
|---|---|
PieDataLabel |
A deep copy of this |
getLabelPosition() Method
Returns the data label position relative to the pie slice.
Declaration
public PieDataLabelPosition getLabelPosition()
Returns
| Type | Description |
|---|---|
| PieDataLabelPosition | The data label position. |
getShowPercent() Method
Returns whether the data label displays the percentage value.
Declaration
public boolean getShowPercent()
Returns
| Type | Description |
|---|---|
| boolean |
|
setLabelPosition(PieDataLabelPosition value) Method
Sets the data label position relative to the pie slice.
Declaration
public void setLabelPosition(PieDataLabelPosition value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | PieDataLabelPosition | The data label position. |
Exceptions
| Type | Description |
|---|---|
| NullPointerException | Thrown if the |
Remarks
The setLabelPosition(value) method accepts the following values:
| Value | Description |
|---|---|
| CENTER | Indicates that the data label is in the center of the pie slice. |
| BEST_FIT | Indicates that the chart application chooses the best data label position. |
| INSIDE_END | Indicates that the data label is inside the pie slice at the outer edge. |
| OUTSIDE_END | Indicates that the data label is outside the pie slice beyond the outer edge. |
| DEFAULT | Indicates that the data label position is not specified, and the chart application uses the default position. |
If you do not call the setLabelPosition(value) method, the API uses PieDataLabelPosition.DEFAULT for a new data label and the value from the document for a loaded data label.
setShowPercent(boolean value) Method
Sets whether to display the percentage value in the data label.
Declaration
public void setShowPercent(boolean value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | boolean |
|
Remarks
If you do not call the setShowPercent(value) method, the API uses false for a new data label and the value from the document for a loaded data label.