Vico charting library for Android. Use when building Cartesian charts (line, column/bar), formatting axes, styling with Material 3 themes, or implementing custom markers. Covers Vico 2.x API with CartesianChartHost and CartesianChartModelProducer patterns.
Vico is a light, extensible, and Compose-first charting library for Android.
CRITICAL AI INSTRUCTION: Vico underwent a major API overhaul in version 2.0. You MUST use the 2.x nomenclature. Do NOT use Vico 1.x classes like ChartEntryModel, ChartEntryModelProducer, lineChart(), or columnChart().
Always use the Cartesian prefix for standard 2D charts.
ChartEntryModelChartEntryModelProducerChartCartesianChartModel, CartesianChartModelProducer, CartesianChartHostEnsure the following dependencies are used (or inferred):
implementation("com.patrykandpatrick.vico:compose:2.0.0-alpha.x")
implementation("com.patrykandpatrick.vico:compose-m3:2.0.0-alpha.x")
implementation("com.patrykandpatrick.vico:core:2.0.0-alpha.x")
Data must be decoupled from the UI. Use CartesianChartModelProducer hoisted in a ViewModel or high-level state, NOT instantiated inside the drawing Composable.
// In ViewModel
val modelProducer = CartesianChartModelProducer()
// Updating data (run inside a coroutine/viewModelScope)
modelProducer.runTransaction {
lineSeries { series(xValues, yValues) }
// OR
columnSeries { series(xValues, yValues) }
}
Charts are constructed using CartesianChartHost, wrapping a CartesianChart with specific layers.
@Composable
fun MyLineChart(modelProducer: CartesianChartModelProducer) {
CartesianChartHost(
chart = rememberCartesianChart(
rememberLineCartesianLayer(),
startAxis = VerticalAxis.rememberStart(),
bottomAxis = HorizontalAxis.rememberBottom()
),
modelProducer = modelProducer,
)
}
@Composable
fun MyColumnChart(modelProducer: CartesianChartModelProducer) {
CartesianChartHost(
chart = rememberCartesianChart(
rememberColumnCartesianLayer(),
startAxis = VerticalAxis.rememberStart(),
bottomAxis = HorizontalAxis.rememberBottom()
),
modelProducer = modelProducer,
)
}
CartesianMarker) and pass it to the marker parameter of rememberCartesianChart().CartesianValueFormatter on the axes to format raw Double values into strings.val bottomAxisFormatter = CartesianValueFormatter { value, _ ->
myDateList.getOrNull(value.toInt()) ?: ""
}
HorizontalAxis.rememberBottom(valueFormatter = bottomAxisFormatter)
CartesianChartModelProducer.drawArc as defined in previous app standards, unless Vico's current alpha explicitly supports circular charts well.Modifier.fillMaxWidth().height(250.dp) as the standard sizing constraint for CartesianChartHost unless otherwise specified.