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

Ohlc Series can be created using the FastOhlcRenderableSeries type.

We don't have examples for the OHLC series, but the very similar Candlestick Series can be found in the SciChart Android Examples Suite

OHLC Series Features

The FastOhlcRenderableSeries class is very much alike the FastCandlestickRenderableSeries class. It allows to specify StrokeUp and StrokeDown pens and relative DataPointWidth which will be applied to every bar.

The DataPointWidth specifies how much space a single bar occupies, varying from 0 to 1 (when bars are conjoined). 

The StrokeUp style is applied to bars with Close > Open, and StrokeDown to those having Open <= Close respectively. Please refer to the articles under the Styling and Theming section to learn more about Brushes and Pens used in SciChart.

Those values can be assigned via the corresponding methods, setStrokeUpStyle(), setStrokeDownStyle() and setDataPointWidth().

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 OHLC Series

To create a FastOhlcRenderableSeries instance, use the following code:

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

// Create PenStyles for Up Stroke, Down Stroke
PenStyle strokeUpStyle = new SolidPenStyle(0xFF00AA00, true, 1, null);
PenStyle strokeDownStyle = new SolidPenStyle(0xFFFF0000, true, 1, null);

// Create and configure the OHLC Chart Series
FastOhlcRenderableSeries ohlcSeries = new FastOhlcRenderableSeries();

ohlcSeries.setStrokeUpStyle(strokeUpStyle);
ohlcSeries.setStrokeDownStyle(strokeDownStyle);

// Set relative width for bars
ohlcSeries.setDataPointWidth(0.8d);

// Create a DataSeries for the chart series
IOhlcDataSeries<Date, Double> dataSeries = new OhlcDataSeries<>(Date.class, Double.class);

// Assume some data has been added to the dataSeries here
// dataSeries.append(Date, Open, High, Low, Close);

// Assign the dataSeries to the chart series
ohlcSeries.setDataSeries(dataSeries);

// Add the chart series to the RenderableSeriesCollection of the surface
Collections.addAll(surface.getRenderableSeries(), ohlcSeries);

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
IOhlcDataSeries<Date, Double> dataSeries = new OhlcDataSeries(Date.class, Double.class);

// Assume some data has been added to the dataSeries here
// dataSeries.append(Date, Open, High, Low, Close);

// Create and configure the Candlestick Chart Series
final FastCandlestickRenderableSeries candlestickSeries = sciChartBuilder.newOhlcSeries()
        .withStrokeUp(0xFF00AA00)
        .withStrokeDown(0xFFFF0000)
        .withDataSeries(dataSeries)
        .build();

// Add the chart series to the RenderableSeriesCollection of the surface
Collections.addAll(surface.getRenderableSeries(), candlestickSeries);

Render a Gap in a OHLC Series

It is possible to show a gap in a Renderable Series by passing a data point with NaN values as the Open, High, Low, Close values. Please refer to the Common RenderableSeries Features article for more details.

Paint Individual Bars With Different Colors

This can be achieved with the PaletteProvider API. It allows to change the fill color of any bar within an OHLC Series. To do this, a custom IStrokePaletteProvider has to be provided to the setPaletteProvider() method.  Please refer to the PaletteProvider API article for more info.

See Also