Skip to main content

HistogramSeries Class

A series in a histogram chart.

Declaration

public class HistogramSeries extends DataSeriesExBase

Remarks

Add a HistogramSeries object to the ChartEx.getSeries() collection to create a histogram chart. A histogram groups series values into bins and displays the number of values in each bin as a column.

Call the setBinType(HistogramBinType value) method to specify how the series calculates bins. Call setOverflowType(HistogramOverflowType value) and setUnderflowType(HistogramOverflowType value) methods to combine values beyond boundaries into a single bin.

To display a cumulative percentage line, add a ParetoSeries object that refers to the histogram series.

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

Example

Create a Histogram Chart with an Overflow Bin

The following code snippet creates a histogram chart that groups values into bins of a specified width, combines values above a boundary into an overflow bin, and displays 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.
            ChartEx chart = new ChartEx();
            chart.setWidth(presentation.getSlideSize().getWidth());
            chart.setHeight(presentation.getSlideSize().getHeight());
            slide.getShapes().add(chart);

            // Create a histogram series and specify data.
            HistogramSeries series = new HistogramSeries();
            series.setText("Delivery Time");
            series.setValues(new ChartNumericData(List.of(
                    2.0, 3.0, 4.0, 4.0, 5.0, 6.0, 6.0, 7.0, 8.0, 9.0,
                    11.0, 12.0, 14.0, 15.0, 18.0, 22.0, 27.0, 35.0)));

            // Group values into bins of 5 days and combine values above 20 days.
            series.setBinType(HistogramBinType.BIN_SIZE);
            series.setBinSize(5);
            series.setOverflowType(HistogramOverflowType.FIXED);
            series.setOverflow(20);

            // Display the number of values in each bin.
            series.getDataLabels().setShowValue(true);
            series.getDataLabels().setLabelPosition(HistogramDataLabelPosition.OUTSIDE_END);
            chart.getSeries().add(series);

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

 Histogram chart with fixed-width bins, an overflow bin, and 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

HistogramSeries()

Initializes a new instance of the HistogramSeries class.

Declaration

public HistogramSeries()

Methods

deepClone() Method

Creates a copy of the histogram series.

Declaration

public HistogramSeries deepClone()

Returns

Type Description
HistogramSeries

A copy of the histogram series.

getBinCount() Method

Returns the number of bins.

Declaration

public int getBinCount()

Returns

Type Description
int

The number of bins.

getBinSize() Method

Returns the bin width.

Declaration

public double getBinSize()

Returns

Type Description
double

The bin width.

getBinType() Method

Returns the bin type of the histogram.

Declaration

public HistogramBinType getBinType()

Returns

Type Description
HistogramBinType

The bin type.

getChartType() Method

Returns the chart type of the series.

Declaration

public ChartExType getChartType()

Returns

Type Description
ChartExType

ChartExType.HISTOGRAM.

getDataLabels() Method

Returns data label settings for the series.

Declaration

public IHistogramDataLabels getDataLabels()

Returns

Type Description
IHistogramDataLabels

Data label settings.

Remarks

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

getOverflow() Method

Returns the boundary of the overflow bin.

Declaration

public double getOverflow()

Returns

Type Description
double

The boundary value.

getOverflowType() Method

Returns the type of the overflow bin boundary.

Declaration

public HistogramOverflowType getOverflowType()

Returns

Type Description
HistogramOverflowType

The boundary type.

getUnderflow() Method

Returns the boundary of the underflow bin.

Declaration

public double getUnderflow()

Returns

Type Description
double

The boundary value.

getUnderflowType() Method

Returns the type of the underflow bin boundary.

Declaration

public HistogramOverflowType getUnderflowType()

Returns

Type Description
HistogramOverflowType

The boundary type.

setBinCount(int value) Method

Sets the number of bins.

Declaration

public void setBinCount(int value)

Parameters

Name Type Description
value int

The number of bins.

Remarks

Note

The number of bins takes effect when you call the setBinType(HistogramBinType.BIN_COUNT) method.

setBinSize(double value) Method

Sets the bin width.

Declaration

public void setBinSize(double value)

Parameters

Name Type Description
value double

The bin width.

Remarks

Note

The bin width takes effect when you call the setBinType(HistogramBinType.BIN_SIZE) method.

setBinType(HistogramBinType value) Method

Sets the bin type of the histogram.

Declaration

public void setBinType(HistogramBinType value)

Parameters

Name Type Description
value HistogramBinType

The bin type.

Remarks

The setBinType(value) method accepts the following values:

Value Description
AUTOMATIC Indicates that the chart calculates the bin width from series data.
BIN_SIZE Indicates bins of a specified width.
BIN_COUNT Indicates a specified number of bins.
BY_CATEGORY Indicates a bin for each category. The bin value is the sum of values in the category.

If you do not call the setBinType(value) method, the API uses HistogramBinType.AUTOMATIC.

Call the setBinSize(double value) method to specify the bin width for the HistogramBinType.BIN_SIZE bin type. Call the setBinCount(int value) method to specify the number of bins for the HistogramBinType.BIN_COUNT bin type.

setOverflow(double value) Method

Sets the boundary of the overflow bin.

Declaration

public void setOverflow(double value)

Parameters

Name Type Description
value double

The boundary value.

Remarks

The overflow bin combines values greater than the boundary.

Note

The boundary takes effect when you call the setOverflowType(HistogramOverflowType.FIXED) method.

setOverflowType(HistogramOverflowType value) Method

Sets the type of the overflow bin boundary.

Declaration

public void setOverflowType(HistogramOverflowType value)

Parameters

Name Type Description
value HistogramOverflowType

The boundary type.

Remarks

The value parameter accepts the following values:

Value Description
NONE Indicates that the histogram has no overflow or underflow bin.
AUTOMATIC Indicates that the chart calculates the overflow or underflow bin boundary from series data.
FIXED Indicates that the overflow or underflow bin uses a specified boundary value.

The overflow bin combines values greater than the boundary. If you do not call the setOverflowType(value) method, the API uses HistogramOverflowType.NONE, and the histogram has no overflow bin.

Call the setOverflow(double value) method to specify the boundary for the HistogramOverflowType.FIXED type.

setUnderflow(double value) Method

Sets the boundary of the underflow bin.

Declaration

public void setUnderflow(double value)

Parameters

Name Type Description
value double

The boundary value.

Remarks

The underflow bin combines values less than or equal to the boundary.

Note

The boundary takes effect when you call the setUnderflowType(HistogramOverflowType.FIXED) method.

setUnderflowType(HistogramOverflowType value) Method

Sets the type of the underflow bin boundary.

Declaration

public void setUnderflowType(HistogramOverflowType value)

Parameters

Name Type Description
value HistogramOverflowType

The boundary type.

Remarks

The value parameter accepts the following values:

Value Description
NONE Indicates that the histogram has no overflow or underflow bin.
AUTOMATIC Indicates that the chart calculates the overflow or underflow bin boundary from series data.
FIXED Indicates that the overflow or underflow bin uses a specified boundary value.

The underflow bin combines values less than or equal to the boundary. If you do not call the setUnderflowType(value) method, the API uses HistogramOverflowType.NONE, and the histogram has no underflow bin.

Call the setUnderflow(double value) method to specify the boundary for the HistogramOverflowType.FIXED type.