LineCartesianLayer
Use LineCartesianLayer to create line charts. Instantiate it via rememberLineCartesianLayer.
Each line is associated with a Line instance. Create these via rememberLine. These are provided by LineProvider. A base implementation of this interface can be instantiated via LineProvider.series. You can customize line fills, backgrounds, shapes, and other properties. You can also add data labels, points, and interpolation.
Animation
Line animations are configured via CartesianLayerDrawingModelInterpolator.line. By default, a line grows from the baseline and fades in during its initial animation. Set sweep to true to instead animate the initial appearance as a clip sweeping in from the start edge:
rememberLineCartesianLayer(
drawingModelInterpolator = CartesianLayerDrawingModelInterpolator.line(sweep = true),
/* ... */
)LineStroke
Line strokes are customized via LineStroke, which has two implementations:
LineFill and AreaFill
Line fills are customized via LineFill, which has two factory functions:
Area fills, which are optional, are customized via AreaFill. This has similar factory functions to LineFill:
These cover most use cases. You can use both colors and brushes, and you can apply split styling—enabling you to create a line that’s green for positive values and red for negative values, for instance. You can, however, also create your own LineFill and AreaFill implementations.
LineFill.colorScale and AreaFill.colorScale provide another option. These APIs let you define multi-stop styling against the value scale instead of splitting at a single threshold.
For an example of an area fill, see the “Electric-car sales (Norway)” sample chart.

catmullRom interpolationInterpolator
Use Interpolator to define how a line passes through its points. Three built-in implementations are available:
Sharpuses straight line segments.cubicuses cubic Bézier curves.catmullRompasses through all points and keeps collinear segments straight.
The “Electric-car sales (Norway)” sample chart uses catmullRom.
PointProvider
To add points, use PointProvider. PointProvider.single instantiates a base implementation that adds a point for each entry and uses a shared point style. Once again, custom implementations can be created. A common use case for this is styling points individually based on their y-values. For an example, see the “AI test scores” sample chart.
Transaction.lineModel
Line layers use LineCartesianLayerModel instances. When using CartesianChartModelProducer, add them via lineModel:
Each series invocation adds a series to the LineCartesianLayerModel instance. Above, three series are added. series has three overloads (each of which accepts all Number subtypes):
a
varargoverload that takes y-values and uses their indices as the x-valuesan overload that takes a collection of y-values and uses their indices as the x-values
an overload that takes a collection of x-values and a collection of y-values of the same size
Manual LineCartesianLayerModel creation
When creating a CartesianChartModel instance directly, you can add a line-layer model by using build. This function gives you access to the same DSL that lineModel does.
Last updated