LineCartesianLayer

Overview

Use LineCartesianLayerarrow-up-right to create line charts. Each line is associated with a LineCartesianLayer.Linearrow-up-right. The LineCartesianLayer.Lines are provided by a LineCartesianLayer.LineProviderarrow-up-right. A base implementation of this interface can be instantiated via LineCartesianLayer.LineProvider.seriesarrow-up-right. You can customize the lines’ fills, backgrounds, shapes, and other properties. You can also add data labels and points.

Line strokes are customized via LineCartesianLayer.LineStrokearrow-up-right, which has two implementations:

Line fills are customized via LineCartesianLayer.LineFillarrow-up-right, which has two factory functions:

Area fills, which are optional, are customized via LineCartesianLayer.AreaFillarrow-up-right. This has similar factory functions to LineCartesianLayer.LineFill:

These cover most use cases. You can use both solid colors and ShaderProviderarrow-up-rights, 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 LineCartesianLayer.LineFill and LineCartesianLayer.AreaFill implementations.

To add points, use LineCartesianLayer.PointProviderarrow-up-right. LineCartesianLayer.PointProvider.singlearrow-up-right 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.

To create a LineCartesianLayerarrow-up-right, use the XML attributes:

<style name="ChartStyle">
    <item name="layers">line</item>
    <!-- ... -->
</style>

Alternatively, use the LineCartesianLayer constructors:

Transaction.lineSeries

LineCartesianLayers use LineCartesianLayerModelarrow-up-rights. When using a CartesianChartModelProducerarrow-up-right, add LineCartesianLayerModels via lineSeriesarrow-up-right:

Each seriesarrow-up-right invocation adds a series to the LineCartesianLayerModel. Above, three series are added. series has three overloads (each of which accepts all Number subtypes):

  • a vararg overload that takes y-values and uses their indices as the x-values

  • an 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 directly, you can add a LineCartesianLayerModel by using buildarrow-up-right. This function gives you access to the same DSL that lineSeries does.

Sample charts

Last updated