Skip to main content

ErrorBar Class

Contains error bar settings for a chart series.

Declaration

public class ErrorBar extends ChartElementBase

Remarks

To display error bars for a series, add an ErrorBar object to the collection that the series getErrorBars() method returns. The following methods return error bar collections:

A series can contain up to two error bars for different axes (for example, horizontal and vertical error bars in a scatter series).

The setType(ErrorValueType value) method specifies the calculation mode for error amounts, and the setValue(double value) method specifies the error amount. For custom error amounts, call setPlus(IChartValueData value) and setMinus(IChartValueData value) methods.

The setDirection(ErrorBarDirection value) method specifies whether error bars display positive error amounts, negative error amounts, or both. The setShowCap(boolean value) method specifies whether error bars have end caps.

Refer to the following help topic for additional information: Add Error Bars and Trend Lines to Charts — Presentation API for Java.

Example

Add Percentage and Custom Error Bars to a Column Chart

The following code snippet creates a column chart with two series, adds percentage error bars with end caps to the first series, and adds custom positive error bars to the second series:

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

            // Add two column series.
            String[] names = { "2024", "2025" };
            double[][] values = { { 42, 55, 48, 61 }, { 47, 52, 58, 66 } };
            for (int i = 0; i < names.length; i++) {
                BarSeries series = new BarSeries();
                series.setText(names[i]);
                series.setArguments(new ChartStringData(List.of("Q1", "Q2", "Q3", "Q4")));
                series.setValues(new ChartNumericData(List.of(values[i][0], values[i][1], values[i][2], values[i][3])));
                chart.getSeries().add(series);
            }

            // Display 10% error bars with end caps for the first series.
            ErrorBar percentageErrorBar = new ErrorBar();
            percentageErrorBar.setType(ErrorValueType.PERCENTAGE);
            percentageErrorBar.setValue(10);
            percentageErrorBar.setShowCap(true);
            OutlineStyle errorBarLine = new OutlineStyle();
            errorBarLine.setFill(new SolidFill(Color.getDarkRed()));
            percentageErrorBar.setOutlineStyle(errorBarLine);
            ((BarSeries) chart.getSeries().get(0)).getErrorBars().add(percentageErrorBar);

            // Display custom positive error values for the second series.
            ErrorBar customErrorBar = new ErrorBar();
            customErrorBar.setType(ErrorValueType.CUSTOM);
            customErrorBar.setDirection(ErrorBarDirection.PLUS);
            customErrorBar.setPlus(new ChartNumericData(List.of(3.0, 5.0, 4.0, 6.0)));
            customErrorBar.setShowCap(true);
            ((BarSeries) chart.getSeries().get(1)).getErrorBars().add(customErrorBar);

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

 Column chart with percentage and custom error bars 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.initFields()
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

ErrorBar()

Initializes a new instance of the ErrorBar class.

Declaration

public ErrorBar()

Methods

deepClone() Method

Returns a deep copy of this ErrorBar instance.

Declaration

public ErrorBar deepClone()

Returns

Type Description
ErrorBar

A deep copy of this ErrorBar.

getAxis() Method

Returns the axis to which error bars apply.

Declaration

public ErrorBarAxis getAxis()

Returns

Type Description
ErrorBarAxis

The axis to which error bars apply.

getDirection() Method

Returns the error bar direction.

Declaration

public ErrorBarDirection getDirection()

Returns

Type Description
ErrorBarDirection

The error bar direction.

getEffects() Method

Returns shape effect settings for error bars.

Declaration

public ShapeEffectProperties getEffects()

Returns

Type Description
ShapeEffectProperties

Shape effect settings.

getMinus() Method

Returns custom negative error amounts.

Declaration

public IChartValueData getMinus()

Returns

Type Description
IChartValueData

Custom negative error amounts.

getOutlineStyle() Method

Returns line settings for error bars.

Declaration

public OutlineStyle getOutlineStyle()

Returns

Type Description
OutlineStyle

Line settings.

getPlus() Method

Returns custom positive error amounts.

Declaration

public IChartValueData getPlus()

Returns

Type Description
IChartValueData

Custom positive error amounts.

getShowCap() Method

Returns whether error bars display end caps.

Declaration

public boolean getShowCap()

Returns

Type Description
boolean

true if error bars display end caps; otherwise, false.

getType() Method

Returns the calculation mode for error amounts.

Declaration

public ErrorValueType getType()

Returns

Type Description
ErrorValueType

The calculation mode.

getValue() Method

Returns the error amount.

Declaration

public double getValue()

Returns

Type Description
double

The error amount.

setAxis(ErrorBarAxis value) Method

Sets the axis to which error bars apply.

Declaration

public void setAxis(ErrorBarAxis value)

Parameters

Name Type Description
value ErrorBarAxis

The axis to which error bars apply.

Remarks

The setAxis(value) method accepts the following values:

Value Description
AUTO Indicates that the axis is selected automatically.
HORIZONTAL Indicates error bars that apply to the horizontal axis.
VERTICAL Indicates error bars that apply to the vertical axis.

If you do not call the setAxis(value) method, the API uses ErrorBarAxis.AUTO.

setDirection(ErrorBarDirection value) Method

Sets the error bar direction.

Declaration

public void setDirection(ErrorBarDirection value)

Parameters

Name Type Description
value ErrorBarDirection

The error bar direction.

Remarks

The setDirection(value) method accepts the following values:

Value Description
BOTH Displays both positive and negative error amounts.
MINUS Displays negative error amounts.
PLUS Displays positive error amounts.

If you do not call the setDirection(value) method, the API uses ErrorBarDirection.BOTH.

setEffects(ShapeEffectProperties value) Method

Sets shape effect settings for error bars.

Declaration

public void setEffects(ShapeEffectProperties value)

Parameters

Name Type Description
value ShapeEffectProperties

Shape effect settings.

Remarks

For a new ErrorBar object, the getEffects() method returns null.

setMinus(IChartValueData value) Method

Sets custom negative error amounts.

Declaration

public void setMinus(IChartValueData value)

Parameters

Name Type Description
value IChartValueData

Custom negative error amounts.

Exceptions

Type Description
ArgumentException

Thrown if the error bar is in a chart on a slide and the value parameter refers to a cell range that is not a single cell, row, or column. The exception message is “The chart data reference must identify a single cell, row, or column.”

Remarks

Custom error amounts apply if the calculation mode is ErrorValueType.CUSTOM (setType(ErrorValueType value)). Pass a ChartNumericData object with error amounts or a ChartDataReference or ChartDataExpressionReference object that refers to chart data cells.

The setPlus(IChartValueData value) method specifies custom positive error amounts.

setOutlineStyle(OutlineStyle value) Method

Sets line settings for error bars.

Declaration

public void setOutlineStyle(OutlineStyle value)

Parameters

Name Type Description
value OutlineStyle

Line settings.

Remarks

Line settings include the line color, width, and dash style. For a new ErrorBar object, the getOutlineStyle() method returns null.

setPlus(IChartValueData value) Method

Sets custom positive error amounts.

Declaration

public void setPlus(IChartValueData value)

Parameters

Name Type Description
value IChartValueData

Custom positive error amounts.

Exceptions

Type Description
ArgumentException

Thrown if the error bar is in a chart on a slide and the value parameter refers to a cell range that is not a single cell, row, or column. The exception message is “The chart data reference must identify a single cell, row, or column.”

Remarks

Custom error amounts apply if the calculation mode is ErrorValueType.CUSTOM (setType(ErrorValueType value)). Pass a ChartNumericData object with error amounts or a ChartDataReference or ChartDataExpressionReference object that refers to chart data cells.

The setMinus(IChartValueData value) method specifies custom negative error amounts.

setShowCap(boolean value) Method

Sets whether to display end caps for error bars.

Declaration

public void setShowCap(boolean value)

Parameters

Name Type Description
value boolean

true to display end caps; otherwise, false.

Remarks

If you do not call the setShowCap(value) method, error bars have no end caps.

setType(ErrorValueType value) Method

Sets the calculation mode for error amounts.

Declaration

public void setType(ErrorValueType value)

Parameters

Name Type Description
value ErrorValueType

The calculation mode.

Remarks

The setType(value) method accepts the following values:

Value Description
FIXED_VALUE Uses a fixed error amount for all data points.
PERCENTAGE Uses a percentage of each data point value.
STANDARD_DEVIATION Uses a multiple of the standard deviation.
STANDARD_ERROR Uses the standard error.
CUSTOM Uses custom error amounts specified by the ErrorBar.setPlus(value) and ErrorBar.setMinus(value) methods.

If you do not call the setType(value) method, the API uses ErrorValueType.FIXED_VALUE.

The setValue(double value) method specifies the error amount for fixed value, percentage, and standard deviation modes. For the ErrorValueType.CUSTOM mode, call setPlus(IChartValueData value) and setMinus(IChartValueData value) methods.

setValue(double value) Method

Sets the error amount.

Declaration

public void setValue(double value)

Parameters

Name Type Description
value double

The error amount.

Remarks

The calculation mode specified by the setType(ErrorValueType value) method determines the meaning of the error amount:

Calculation Mode Error Amount
ErrorValueType.FIXED_VALUE A fixed value for all data points.
ErrorValueType.PERCENTAGE A percentage of each data point value (for example, 10 for 10%).
ErrorValueType.STANDARD_DEVIATION The number of standard deviations.

If the calculation mode is ErrorValueType.CUSTOM or ErrorValueType.STANDARD_ERROR, the API ignores the error amount. For custom error bars, call setPlus(IChartValueData value) and setMinus(IChartValueData value) methods.