CartesianMarker
CartesianMarker instances highlight points on charts. There are two types:
Standard markers are shown on tap. These are added to a chart via the
markerconstructor parameter.Persistent markers are shown permanently at given x-values. These are added to a chart via the
persistentMarkersconstructor parameter.
There are two ways of creating CartesianMarker instances:
using
DefaultCartesianMarker, described belowcreating a custom implementation of the interface
DefaultCartesianMarker
DefaultCartesianMarkerA common means of creating CartesianMarker instances is DefaultCartesianMarker, which accepts three main components—a label, a point indicator, and a vertical line—and offers several customization options.
DefaultCartesianMarker label text is created by DefaultCartesianMarker.ValueFormatter. A dedicated formatting contract is required here because CartesianMarker instances 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
CartesianMarkerVisibilityListenerYou can listen for visibility changes of standard markers via CartesianMarkerVisibilityListener.
CartesianMarkerController
CartesianMarkerControllerBy default, a standard marker appears on press and disappears on release. You can customize this with CartesianMarkerController, which has built-in implementations instantiated via the following:
CartesianMarkerController.showOnPress(default)
For more specific behavior, create a custom implementation.
CartesianMarker.Target
CartesianMarker.TargetCartesianMarker instances use CartesianMarker.Target instances, which hold information on the highlighted points. They are stored in lists (called targets), since several points may be highlighted at once.
CartesianMarker.Target 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:
If you know that only one point can be highlighted at once, use
targets.first(). (This occurs when each point has a unique pixel x-coordinate—for example, when only a single-seriesLineCartesianLayerMarkerTargetis present.) Otherwise, iteratetargets.If you know that only one kind of
CartesianMarker.Targetis present, use casting. (This occurs when only one kind ofCartesianLayeris in use.) Otherwise, use type checking (whenwithis).
Last updated