Skip to main content

ChartOfPieSeries Class

A series in a pie of pie or bar of pie chart.

Declaration

public class ChartOfPieSeries extends PieSeries

Remarks

Add a ChartOfPieSeries object to the Chart.getSeries() collection to create a pie of pie or bar of pie chart. The chart creates a ChartOfPieView object for the series.

A pie of pie or bar of pie chart moves data points from the main pie to a secondary plot. The main pie displays the moved data points as a single slice. Call ChartOfPieView.setSecondChartType(value) and ChartOfPieView.setSplitType(value) methods to specify the secondary plot type and the data points that move to the secondary plot.

Refer to the following help topic for additional information: Create Standard Charts — Presentation API for Java.

Example

Create a Bar of Pie Chart

The following code snippet creates a bar of pie chart that moves data points with values less than 15 to a secondary bar and connects the plots with series lines:

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);

            // Create a series for a bar of pie chart.
            ChartOfPieSeries series = new ChartOfPieSeries();
            series.setText("Sales by Region");
            series.setArguments(new ChartStringData(List.of("North", "South", "East", "West", "Online", "Partners")));
            series.setValues(new ChartNumericData(List.of(32.0, 25.0, 21.0, 12.0, 6.0, 4.0)));
            chart.getSeries().add(series);

            // Move data points with values less than 15 to a secondary bar.
            ChartOfPieView view = (ChartOfPieView) chart.getViews().get(0);
            view.setSecondChartType(ChartOfPieType.BAR);
            view.setSplitType(ChartOfPieSplitType.VALUE);
            view.setSplitPosition(15);
            view.setGapWidth(80);
            view.setVaryColors(true);

            // Draw gray series lines between the plots.
            OutlineStyle seriesLine = new OutlineStyle();
            seriesLine.setFill(new SolidFill(Color.getGray()));
            ChartElement seriesLineProperties = new ChartElement();
            seriesLineProperties.setOutlineStyle(seriesLine);
            view.setSeriesLineProperties(seriesLineProperties);

            // Display category names and values in data labels.
            view.getDataLabels().setShowCategoryName(true);
            view.getDataLabels().setShowValue(true);

            // 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:

 Bar of pie chart with series lines and category names in data labels created with the DevExpress Presentation API for Java

Inherited Members

com.devexpress.system.JavaObject.clone()
com.devexpress.system.JavaObject.equals(java.lang.Object)
com.devexpress.system.JavaObject.hashCode()
com.devexpress.system.JavaObject.memberwiseClone()
com.devexpress.system.JavaObject.toString()
java.lang.Object.finalize()
java.lang.Object.getClass()
java.lang.Object.notify()
java.lang.Object.notifyAll()
java.lang.Object.wait()
java.lang.Object.wait(long)
java.lang.Object.wait(long,int)

Inheritance

Object
See Also

ChartOfPieSeries()

Initializes a new instance of the ChartOfPieSeries class.

Declaration

public ChartOfPieSeries()