SciChart Android 2D Charts API > 2D Chart Types > The Error Bars Series Type
The Error Bars Series Type

In SciChart, Error Bar Series is represented by the FastErrorBarsRenderableSeries and FastFixedErrorBarsRenderableSeries types.

Examples for the Error Bars Series can be found in the SciChart Android Examples Suite

Error Bar Series Features

Error Bar Series allow to render error bars for every data point. This can be achieved by setting ErrorDirection to either Vertical error or Horizontal error. It is possible to show either HighErrorLowError or Both by setting ErrorMode:

ErrorType specifies whether error value is Relative (a fraction between 0 and 1) or Absolute. All these can be set via the corresponding methods: setErrorDirection(), setErrorMode(), setErrorType().

Relative DataPointWidth should be used to determine how much space a single bar occupies. This value can vary from 0 to 1 (when bars are conjoined). It can be set via the setDataPointWidth() method.

Error Bars can be colored differently by providing desired pens for StrokeLowStyle or StrokeHighStyle via the setStrokeLowStyle()setStrokeHighStyle() methods. Please refer to the articles under the Styling and Theming section to learn more about Brushes and Pens used in SciChart.

Note:

This series type can be used in tandem with other series types, such as XyScatterRenderableSeries. Error Bars Series can share a DataSeries with other series, to avoid data duplication.

Note:

In multi axis scenarios, a series has to be assigned to particular X and Y axes. This can be done passing the axes IDs to the setXAxisId(), setYAxisId() methods of the series.

Create an Error Bars Series

To create a FastFixedErrorBarsRenderableSeries, use the following code:

// Assume a surface has been created and configured somewhere
ISciChartSurface surface;

// Create a Stroke Pen
PenStyle strokeStyle = new SolidPenStyle(0xFFFF1919, true, 2, null);

// Create an Error Bars Series
FastFixedErrorBarsRenderableSeries verticalErrorBars = new FastFixedErrorBarsRenderableSeries();

// Create a DataSeries for the chart series
IXyDataSeries<Double, Double> dataSeries = new XyDataSeries<>(Double.class, Double.class);
// Assume some data has been added to the dataSeries here
// dataSeries.append(X, Y);

verticalErrorBars.setDataSeries(dataSeries);

// Set StrokeStyle
verticalErrorBars.setStrokeStyle(strokeStyle);

// Specify that error bars should appear in Y-direction
verticalErrorBars.setErrorDirection(ErrorDirection.Vertical);

// Specify that both HighError and LowError have to be drawn
verticalErrorBars.setErrorMode(ErrorMode.Both);

// Set error values
verticalErrorBars.setErrorHigh(0.3);
verticalErrorBars.setErrorLow(0.1);

// Specify that error values are relative
verticalErrorBars.setErrorType(ErrorType.Relative);

// Add the RenderableSeries to the RenderableSeriesCollection of the surface
 Collections.addAll(surface.getRenderableSeries(), bandSeries);

The same can be achieved using Chart Builders:

// Assume a surface has been created and configured somewhere
ISciChartSurface surface;

// Create a DataSeries for the chart series
IXyDataSeries<Double, Double> dataSeries = new XyDataSeries<>(Double.class, Double.class);
// Assume some data has been added to the dataSeries here
// dataSeries.append(X, Y);

// Create and configure an Error Bars Series
FastFixedErrorBarsRenderableSeries horizontalErrorBars = sciChartBuilder.newFixedErrorBarsSeries()
        .withDataSeries(dataSeries)
        .withStrokeStyle(0xFFFF0000)
        .withErrorDirection(ErrorDirection.Horizontal)
        .withErrorType(ErrorType.Absolute)
        .withErrorMode(ErrorMode.Both)
        .withLowError(0.3)
        .withHighError(0.3)
        .build();

// Add the RenderableSeries to the RenderableSeriesCollection of the surface
 Collections.addAll(surface.getRenderableSeries(), horizontalErrorBars);

 

See Also