Skip to main content
Version: 2.0.0-alpha.19

Extra elements

You can add extra elements to CartesianCharts.

Decoration

A Decoration adds an additional layer of data. There are two built-in implementation, described below, and you can add your own. Add a Decoration to a CartesianChart as follows:

CartesianChartHost(chart = rememberCartesianChart(decorations = listOf(...), ...), ...)

HorizontalLine

A HorizontalLine highlights a y value. Create an instance as follows:

rememberHorizontalLine(...)

HorizontalBox

A HorizontalBox highlights a y range. Create an instance as follows:

rememberHorizontalBox(...)

CartesianMarker

CartesianMarkers highlight CartesianChart entries. They can be shown when a CartesianChart is touched, or you can make them persistent. To create a CartesianMarker, you can use DefaultCartesianMarker or implement the interface yourself. CartesianMarkerValueFormatter lets you customize a DefaultCartesianMarker’s label. CartesianMarkerVisibilityListener lets you listen for visibility changes of standard CartesianMarkers.

DefaultCartesianMarkers are created as follows:

rememberDefaultCartesianMarker(...)

See rememberMarker in the sample app for a full and more complex example.

CartesianMarkers are added to CartesianCharts as follows:

CartesianChartHost(marker = ..., ...)

Add a persistent CartesianMarkers to a CartesianChart as follows:

CartesianChartHost(chart = rememberCartesianChart(persistentMarkers = listOf(...), ...), ...)

Legends

A Legend describes the elements present on a CartesianChart. There are two built-in implementations: HorizontalLegend and VerticalLegend. These Legends consist of LegendItems.

Create a HorizontalLegend as follows:

rememberHorizontalLegend(listOf(rememberLegendItem(...), ...), ...)

Create a VerticalLegend as follows:

rememberVerticalLegend(listOf(rememberLegendItem(...), ...), ...)

Add a Legend to a CartesianChart as follows:

CartesianChartHost(chart = rememberCartesianChart(legend = ..., ...), ...)