CartesianChartView

CartesianChartView is the entry point for Cartesian charts in the view system. It accepts CartesianChart and CartesianChartModelProducer instances, facilitates communication between them, and displays the chart. It also handles scroll and zoom and shows a placeholder when no data is available.

CartesianChartView automatically creates a chart when the layers attribute is used:

<style name="ChartStyle">
    <item name="layers"><!-- ... --></item>
    <!-- ... -->
</style>
<com.patrykandpatrick.vico.views.cartesian.CartesianChartView
    app:chartStyle="@style/ChartStyle"
    <!-- ... --> />

Use the CartesianChartView.chart property to get a reference to this chart. Also use it to apply a chart created programmatically:

cartesianChartView.chart = CartesianChart(/* ... */)

Data

Use CartesianChartView.modelProducer to set a CartesianChartModelProducer instance:

cartesianChartView.modelProducer = cartesianChartModelProducer

You can also use a manually created CartesianChartModel instance via the model property:

cartesianChartView.model = model

Multiple layers

You can add multiple layers by separating their names with pipes:

Scroll and zoom

There are XML attributes for toggling scroll and zoom:

More advanced customization uses ScrollHandler and ZoomHandler:

You can also toggle ScrollHandler.scrollEnabled directly.

Scroll represents scroll values—either absolute (from zero) or relative (from the current value). Scroll.Absolute and Scroll.Relative cover the two cases. The following factory functions are available:

AutoScrollCondition defines when to scroll automatically. There are two singletons:

Zoom defines zoom factors. The following singletons and factory functions are available:

While the built-in implementations cover the majority of use cases, you can create custom implementations of Scroll, AutoScrollCondition, and Zoom for more advanced behavior.

Sample charts

Last updated