Skip to main content

DoughnutChartView Class

Contains settings that apply to doughnut series in a chart view.

Declaration

public class DoughnutChartView extends SlicedChartView

Remarks

When you add a DoughnutSeries object to a chart, the chart creates a DoughnutChartView object for the series. Call the Chart.getViews() method to access chart views.

If the chart contains multiple doughnut series, the view displays the series as concentric rings.

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

Example

Create a Doughnut Chart

The following code snippet creates a doughnut chart, separates the slices, enlarges the doughnut hole, and displays category names and percentages in data labels:

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 doughnut series and specify data.
            DoughnutSeries series = new DoughnutSeries();
            series.setText("Market Share");
            series.setArguments(new ChartStringData(List.of("Product A", "Product B", "Product C", "Product D")));
            series.setValues(new ChartNumericData(List.of(45.0, 25.0, 18.0, 12.0)));
            series.setExplosion(0.05f);
            chart.getSeries().add(series);

            // Enlarge the hole, rotate slices, and color each slice differently.
            DoughnutChartView view = (DoughnutChartView) chart.getViews().get(0);
            view.setHoleSize(50);
            view.setFirstSliceAngle(90);
            view.setVaryColors(true);

            // Display category names and percentages in data labels.
            view.getDataLabels().setShowCategoryName(true);
            view.getDataLabels().setShowPercent(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:

 Doughnut chart with separated slices and percentages 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)
See Also

DoughnutChartView()

Initializes a new instance of the DoughnutChartView class.

Declaration

public DoughnutChartView()

Methods

getChartType() Method

Returns the chart type of the view.

Declaration

public ChartType getChartType()

Returns

Type Description
ChartType

ChartType.DOUGHNUT.

getDataLabels() Method

Returns data label settings for all series in the view.

Declaration

public IDoughnutDataLabels getDataLabels()

Returns

Type Description
IDoughnutDataLabels

Data label settings.

Remarks

Call the DoughnutSeries.getDataLabels() method to access data label settings for an individual series.

Refer to the following help topic for additional information: Customize Chart Data Labels — Presentation API for Java.

getHoleSize() Method

Returns the size of the doughnut hole as a percentage of the doughnut size.

Declaration

public int getHoleSize()

Returns

Type Description
int

The hole size as a percentage (from 10 to 90).

setHoleSize(int value) Method

Sets the size of the doughnut hole as a percentage of the doughnut size.

Declaration

public void setHoleSize(int value)

Parameters

Name Type Description
value int

The hole size as a percentage (from 10 to 90).

Exceptions

Type Description
ArgumentOutOfRangeException

Thrown if the value parameter is less than 10 or greater than 90.

Remarks

The value range is from 10 to 90. If you do not call the setHoleSize(value) method, the API uses 10.