ColumnCartesianLayer

Use ColumnCartesianLayerarrow-up-right to create column charts. Columns are drawn via LineComponentarrow-up-right instances provided by ColumnCartesianLayer.ColumnProviderarrow-up-right. ColumnCartesianLayer.ColumnProvider.seriesarrow-up-right creates a ColumnCartesianLayer.ColumnProvider instance that uses one LineComponent instance per series. You can create your own implementation for custom behavior, including styling columns individually based on their y-values.

On a ColumnCartesianLayer instance, you can also change column spacing. Data labels are supported. When multiple series are added, columns can be grouped horizontally or stacked.

To create a ColumnCartesianLayer instance, use the XML attributes:

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

Alternatively, instantiate ColumnCartesianLayer via the constructor:

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

Transaction.columnSeries

Column layers use ColumnCartesianLayerModelarrow-up-right instances. When using CartesianChartModelProducerarrow-up-right, add them via columnSeriesarrow-up-right:

cartesianChartModelProducer.runTransaction {
    columnSeries {
        series(1, 8, 3, 7)
        series(y = listOf(6, 1, 9, 3))
        series(x = listOf(1, 2, 3, 4), y = listOf(2, 5, 3, 4))
    }
    // ...
}

Each seriesarrow-up-right invocation adds a series to the ColumnCartesianLayerModel instance. Above, three series are added. series has three overloads (each of which accepts all Number subtypes):

  • a vararg overload that takes y-values and uses their indices as the x-values

  • an overload that takes a collection of y-values and uses their indices as the x-values

  • an overload that takes a collection of x-values and a collection of y-values of the same size

Manual ColumnCartesianLayerModel creation

When creating a CartesianChartModelarrow-up-right instance directly, you can add a column-layer model by using buildarrow-up-right. This function gives you access to the same DSL that columnSeries does.

Sample charts

Last updated