Jetpack Glance
The compose-glance module lets Jetpack Glance app widgets display Vico charts. Use CartesianChartImage and PieChartImage in widget content. These functions render charts off-screen to bitmaps and display the result as a static Glance image.
This differs from the interactive chart hosts CartesianChartHost and PieChartHost. Glance doesn’t support the Compose canvas, so the image functions are the supported entry points for app widgets. Because the result is static, chart interactions such as scroll, zoom, and markers are unavailable.
Cartesian charts
Pass a CartesianChart instance and a CartesianChartModel instance:
CartesianChartImage(
chart = rememberCartesianChart(rememberLineCartesianLayer()),
model = model,
contentDescription = "Weekly sales",
modifier = GlanceModifier.fillMaxSize(),
)Pie charts
Pass a PieChart instance and a PieChartModel instance:
PieChartImage(
chart = rememberPieChart(),
model = model,
contentDescription = "Expense breakdown",
modifier = GlanceModifier.fillMaxSize(),
)Size and scaling
By default, each image uses Glance’s current widget size. You can pass a custom DpSize value via the size parameter. Use the contentScale parameter, which accepts a ContentScale value, to control how the bitmap is scaled within the image bounds.
Last updated