ColumnCartesianLayer

Use ColumnCartesianLayer to create column charts. Columns are drawn via LineComponent instances provided by ColumnCartesianLayer.ColumnProvider. ColumnCartesianLayer.ColumnProvider.series 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.

Creation

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 ColumnCartesianLayerModel instances. When using CartesianChartModelProducer, add them via columnSeries:

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 series 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 CartesianChartModel instance directly, you can add a column-layer model by using build. This function gives you access to the same DSL that columnSeries does.

Sample charts

Last updated