SciChart Android 2D Charts API > 2D Chart Types > The Candlestick Series type
The Candlestick Series type

Candlestick Series can be created using the FastCandlestickRenderableSeries type.

Examples for the Candlestick Series can be found in the SciChart Android Examples Suite

Candlestick Series Features

The FastCandlestickRenderableSeries class allows to specify FillUp and FillDown brushes, 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). 

StrokeUp and FillUp styles are applied to bars with Close > Open, and StrokeDown and FillDown to those that have 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, setFillUpBrushStyle(), setFillDownBrushStyle(), 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 a Candlestick Series

To create a FastCandlestickRenderableSeries 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 a BrushStyles for Fill
BrushStyle fillUpStyle = new LinearGradientBrushStyle(0, 0, 0, 1, 0x55002200, 0xFF00AA00);
BrushStyle fillDownStyle = new LinearGradientBrushStyle(0, 0, 0, 1, 0x55441111, 0xFFFF0000);

// Create and configure the Candlestick Chart Series
FastCandlestickRenderableSeries candlestickSeries = new FastCandlestickRenderableSeries();

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

candlestickSeries.setFillUpBrushStyle(fillUpStyle);
candlestickSeries.setFillDownBrushStyle(fillDownStyle);

// Set relative width for bars
candlestickSeries.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
candlestickSeries.setDataSeries(dataSeries);

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

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.newCandlestickSeries()
        .withStrokeUp(0xFF00AA00)
        .withStrokeDown(0xFFFF0000)
        .withDataSeries(dataSeries)
        .withFillUpLinearGradientColors(0x55002200, 0xFF00AA00)
        .withFillDownLinearGradientColors(0x55441111, 0xFFFF0000)
        .build();

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

 

Render a Gap in a Candlestick 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 Candlesticks With Different Colors

This can be achieved with the PaletteProvider API. It allows to change the fill color of any bar within a Candlestick Series. To do this, a custom IFillPaletteProvider or IStrokePaletteProvider has to be provided to the setPaletteProvider() method.

 

Please refer to the PaletteProvider API article for more info.

See Also