Markers
CartesianMarker
s highlight points on CartesianChart
s. There are two types of CartesianMarker
:
- Compose
- Views
- Standard
CartesianMarker
s are shown when theCartesianChart
is tapped. Add suchCartesianMarker
s via themarker
parameter ofCartesianChartHost
. - Persistent
CartesianMarker
s are shown permanently. Add them via thepersistentMarkers
parameter ofrememberCartesianChart
.
- Standard
CartesianMarker
s are shown when theCartesianChart
is tapped. Add suchCartesianMarker
s viaCartesianChartView#marker
. - Persistent
CartesianMarker
s are shown permanently. Add them viaCartesianChart#persistentMarkers
.
CartesianMarker
s use CartesianMarker.Target
s, which hold information on the highlighted points. Each CartesianLayer
has its own implementation, giving us CandlestickCartesianLayerMarkerTarget
, ColumnCartesianLayerMarkerTarget
, and LineCartesianLayerMarkerTarget
.
There are two ways of creating a CartesianMarker
:
- using
DefaultCartesianMarker
, described below - creating a custom implementation of the interface
DefaultCartesianMarker
A common means of creating CartesianMarker
s is DefaultCartesianMarker
, which accepts three main components—a label, a point indicator, and a vertical line—and offers several customization options.
- Compose
- Views
Create DefaultCartesianMarker
instances via rememberDefaultCartesianMarker
.
A DefaultCartesianMarker
’s label text is created by its CartesianMarkerValueFormatter
, which you can change via the valueFormatter
parameter of rememberCartesianMarker
.
Create DefaultCartesianMarker
instances via the class constructor.
A DefaultCartesianMarker
’s label text is created by its CartesianMarkerValueFormatter
, which you can change via the valueFormatter
parameter of the DefaultCartesianMarker
constructor.
A dedicated formatting contract is required here because CartesianMarker
s can highlight multiple points at once. The general principle is the same as with CartesianValueFormatter
, but the required information must first be retrieved from targets
.
The default CartesianMarkerValueFormatter
implementation is DefaultCartesianMarkerValueFormatter
, which uses DecimalFormat
to format y values. DefaultCartesianMarkerValueFormatter
lets you provide a custom DecimalFormat
instance and toggle the color-coding of y values. You can use a custom DecimalFormat
instance not only to change how the y values themselves are formatted, but also to add prefixes and suffixes.
DefaultCartesianMarker
is open for subclassing.
CartesianMarkerVisibilityListener
You can listen for visibility changes of standard CartesianMarker
s via CartesianMarkerVisibilityListener
.
- Compose
- Views
Add a CartesianMarkerVisibilityListener
via the markerVisibilityListener
parameter of CartesianChartHost
.