CandlestickCartesianLayer

Use CandlestickCartesianLayerarrow-up-right to create candlestick charts. Each candle’s style is defined by its corresponding Candlearrow-up-right instance. These are provided by CandleProviderarrow-up-right:

  • To style candles based on their absolute price changes (closing vs. opening), use absolutearrow-up-right. This is commonly used for filled candles.

  • To style candles based on both their absolute price changes (closing vs. opening) and their relative price changes (closing vs. previous closing), use absoluteRelativearrow-up-right. This is commonly used for hollow candles.

  • For custom behavior, implement CandleProvider.

On a CandlestickCartesianLayer instance, you can set the minimum body height, change the candle spacing, and toggle wick scaling.

To create a CandlestickCartesianLayer instance, use the XML attributes:

<style name="ChartStyle">
    <item name="layers">candlestick</item>
    <!-- ... -->
</style>
<com.patrykandpatrick.vico.views.cartesian.CartesianChartView
    app:chartStyle="@style/ChartStyle"
    <!-- ... --> />

Alternatively, instantiate CandlestickCartesianLayer via the constructor:

cartesianChartView.chart = CartesianChart(CandlestickCartesianLayer(/* ... */), /* ... */)

Transaction.candlestickSeries

Candlestick layers use CandlestickCartesianLayerModelarrow-up-right instances. When using CartesianChartModelProducerarrow-up-right, add them via candlestickSeriesarrow-up-right:

cartesianChartModelProducer.runTransaction {
    candlestickSeries(
        x = listOf(1, 2, 3, 4),
        opening = listOf(2, 4, 6, 3),
        closing = listOf(4, 5, 3, 3),
        low = listOf(1, 4, 2, 2),
        high = listOf(5, 6, 7, 4),
    )
    // ...
}

candlestickSeries also has an overload with no x parameter, which uses the indices of the prices as the x-values:

Manual CandlestickCartesianLayerModel creation

When creating a CartesianChartModelarrow-up-right instance directly, you can add a candlestick-layer model by using buildarrow-up-right:

This function also has an overload with no x parameter:

Sample charts

Last updated