Extra elements
You can add extra elements to CartesianChart
s.
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:
- Compose
- Views
CartesianChartHost(chart = rememberCartesianChart(decorations = listOf(...), ...), ...)
cartesianChartView.addDecoration(...)
HorizontalLine
A HorizontalLine
highlights a y value. Create an instance as follows:
- Compose
- Views
rememberHorizontalLine(...)
HorizontalLine(...)
HorizontalBox
A HorizontalBox
highlights a y range. Create an instance as follows:
- Compose
- Views
rememberHorizontalBox(...)
HorizontalBox(...)
CartesianMarker
CartesianMarker
s 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 CartesianMarker
s.
DefaultCartesianMarker
s are created as follows:
- Compose
- Views
rememberDefaultCartesianMarker(...)
See rememberMarker
in the sample app for a full and more complex example.
DefaultCartesianMarker(...)
CartesianMarker
s are added to CartesianChart
s as follows:
- Compose
- Views
CartesianChartHost(marker = ..., ...)
cartesianChartView.marker = ...
Add a persistent CartesianMarker
s to a CartesianChart
as follows:
- Compose
- Views
CartesianChartHost(chart = rememberCartesianChart(persistentMarkers = listOf(...), ...), ...)
cartesianChartView.chart.addPersistentMarker(...)
Legends
A Legend
describes the elements present on a CartesianChart
. There are two built-in implementations: HorizontalLegend
and VerticalLegend
. These Legend
s consist of LegendItem
s.
Create a HorizontalLegend
as follows:
- Compose
- Views
rememberHorizontalLegend(listOf(rememberLegendItem(...), ...), ...)
HorizontalLegend(listOf(LegendItem(...), ...), ...)
Create a VerticalLegend
as follows:
- Compose
- Views
rememberVerticalLegend(listOf(rememberLegendItem(...), ...), ...)
VerticalLegend(listOf(LegendItem(...), ...), ...)
Add a Legend
to a CartesianChart
as follows:
- Compose
- Views
CartesianChartHost(chart = rememberCartesianChart(legend = ..., ...), ...)
cartesianChartView.chart.legend = ...