Introduction
CartesianChart
s stack CartesianLayer
s. The three built-in CartesianLayer
s, all of which extend BaseCartesianLayer
, are described on the following pages.
A CartesianChart
’s x and y ranges depend on those reported by its CartesianLayer
s. The x range is the narrowest one that includes all CartesianLayer
s’ x ranges. By default, there’s an analogously determined shared y range.
verticalAxisPosition
A CartesianChart
can have two separate y ranges, one for the start VerticalAxis
and one for the end VerticalAxis
. (Technically, the presence of two VerticalAxis
instances isn’t necessary, but it’s generally needed for unambiguity.) To utilize this functionality, use the verticalAxisPosition
parameters and properties to assign each CartesianLayer
an AxisPosition.Vertical
subclass—either AxisPosition.Vertical.Start
or AxisPosition.Vertical.End
. The final y range for either AxisPosition.Vertical
subclass is the narrowest range that includes the y ranges of all CartesianLayer
s linked to that AxisPosition.Vertical
subclass. Thus, you get two independently scaled groups of CartesianLayer
s, and the two VerticalAxis
instances are disconnected.
AxisValueOverrider
What x and y ranges a CartesianLayer
reports depends on its AxisValueOverrider
.
- Compose
- Views
Set a CartesianLayer
’s AxisValueOverrider
via the axisValueOverrider
parameters of rememberCandlestickCartesianLayer
, rememberColumnCartesianLayer
, and rememberLineCartesianLayer
.
A CartesianLayer
passes its intrinsic x and y ranges—which depend on the CartesianLayerModel
—to its AxisValueOverrider
, and the AxisValueOverrider
returns the final ranges for the CartesianLayer
to report. There are three AxisValueOverrider
factory functions:
For more specific behavior, create a custom implementation.
The default implementations of the AxisValueOverrider
functions leave the x range unchanged but do these two things:
- They ensure that the y range includes zero.
- They apply a y range of [0, 1] if the minimum and maximum intrinsic y values are both zero.
This also applies to the AxisValueOverrider
implementations returned by AxisValueOverrider.auto
and AxisValueOverrider.adaptiveYValues
. Custom AxisValueOverrider
implementations can override this behavior. With AxisValueOverrider.fixed
, minY
and maxY
take precedence.
When using CartesianChartModelProducer
, set each CartesianLayer
’s AxisValueOverrider
only once. There are no restrictions on dynamic behavior, but it should be implemented as part of a single AxisValueOverrider
, not by means of an AxisValueOverrider
-switching mechanism.
When the CartesianLayer
’s intrinsic x and y ranges are needed for calculations, use the values passed to the AxisValueOverrider
functions (unless, of course, you’re using AxisValueOverrider.auto
or AxisValueOverrider.adaptiveYValues
). Beyond that, use extras if needed. These are important here not only for the usual synchronization reasons, but also because they’re updated via CartesianChartModelProducer.Transaction
s, and a CartesianChartModelProducer.Transaction
is required for a CartesianChart
’s x and y ranges to be updated. A common use case for extras is switching between predefined x and y ranges, including without series updates.
It can be concluded that in CartesianChartModelProducer
-powered charts, AxisValueOverrider.fixed
should be used only for predefined overrides that don’t directly depend on the data and never change.