Vico

2.9. CartesianMarker

2.9.1. Overview

CartesianMarkers highlight points on CartesianCharts. There are two types of CartesianMarker:

There are two ways of creating a CartesianMarker:

2.9.2. DefaultCartesianMarker

A common means of creating CartesianMarkers is DefaultCartesianMarker, which 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 CartesianMarkerValueFormatter. A dedicated formatting contract is required here because CartesianMarkers 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 (2.9.4).

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.

See 5.5 for DefaultCartesianMarker creation in Compose.

2.9.3. CartesianMarkerVisibilityListener

You can listen for visibility changes of standard CartesianMarkers via CartesianMarkerVisibilityListener.

2.9.4. CartesianMarker.Target

CartesianMarkers use CartesianMarker.Targets, which hold information on the highlighted points. They are stored in lists (called targets), since several points may be highlighted at once.

CartesianMarker.Targets itself includes only general properties. More data is found in its implementations, each of which corresponds to a CartesianLayer: CandlestickCartesianLayerMarkerTarget, ColumnCartesianLayerMarkerTarget, and LineCartesianLayerMarkerTarget.

In general, you should take the following approach when working with targets: