CartesianMarker
CartesianMarker
s highlight points on CartesianChart
s. There are two types of CartesianMarker
:
CartesianMarker
s are shown on tap. Add these via the marker
parameter of rememberCartesianChart
.CartesianMarker
s are shown permanently at given x-values. Add these via the persistentMarkers
parameter of rememberCartesianChart
.There are two ways of creating a CartesianMarker
:
DefaultCartesianMarker
, described belowDefaultCartesianMarker
A common means of creating CartesianMarker
s is DefaultCartesianMarker
, instantiated via rememberDefaultCartesianMarker
. It accepts three main components—a label, a point indicator, and a vertical line—and offers several customization options.
A DefaultCartesianMarker
’s label text is created by its DefaultCartesianMarker.ValueFormatter
. 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
.
A base DefaultCartesianMarker.ValueFormatter
implementation can be instantiated via DefaultCartesianMarker.ValueFormatter.default
. This implementation uses DecimalFormat
to format y-values. You can provide a custom DecimalFormat
instance and toggle the color-coding of y-values. The former enables you 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
.
CartesianMarker.Target
CartesianMarker
s use CartesianMarker.Target
s, which hold information on the highlighted points.
They are stored in lists (called targets
), since several points may be highlighted at once.
CartesianMarker.Target
s itself includes only general properties. More data is found in its subtypes,
each of which corresponds to a CartesianLayer
: CandlestickCartesianLayerMarkerTarget
,
ColumnCartesianLayerMarkerTarget
, and LineCartesianLayerMarkerTarget
.
In general, you should take the following approach when working with targets
:
targets.first()
. (This occurs when each point has a
unique pixel x-coordinate—for example, when only a single-series LineCartesianLayerMarkerTarget
is
present.) Otherwise, iterate targets
.CartesianMarker.Target
is present, use casting. (This occurs when only one
kind of CartesianLayer
is in use.) Otherwise, use type checking (when
with is
).