Charts (Android)
Use charts in Android widgets to show trends, comparisons, progress, or composition at a glance. You can mix bars, lines, areas, points, rules, and sectors in a single chart.
Charts are rendered to a bitmap using the Android Canvas API and displayed as a Glance Image. This approach is required because Jetpack Glance has no native charting components.
Mark components (BarMark, LineMark, and the other mark types) must be direct children of <VoltraAndroid.Chart>. Do not wrap them in a custom component.
Basic Usage
Wrap one or more mark components inside <VoltraAndroid.Chart>:
Data Types
All marks except RuleMark take a data prop. There are two data shapes depending on the mark type:
Marks
BarMark
Use bars when people need to compare values across categories.
Parameters:
data(ChartDataPoint[], required): The data points.color(string, optional): Fill color.cornerRadius(number, optional): Rounded bar corners.width(number, optional): Fixed bar width.stacking(string, optional):"grouped"for side-by-side bars in a multi-series chart.
LineMark
Use a line when the shape of change matters more than individual columns.
Parameters:
data(ChartDataPoint[], required): The data points.color(string, optional): Line color.lineWidth(number, optional): Stroke width.interpolation(string, optional):"linear","monotone","catmullRom","cardinal","stepStart","stepCenter", or"stepEnd".
AreaMark
Use an area chart when you want the overall volume or rise/fall pattern to read quickly.
Parameters:
data(ChartDataPoint[], required): The data points.color(string, optional): Fill color.interpolation(string, optional): Same options asLineMark.
PointMark
Use points for sparse measurements, scatter plots, or to emphasize exact observations.
Parameters:
data(ChartDataPoint[], required): The data points.color(string, optional): Point color.symbolSize(number, optional): Point size.
RuleMark
A horizontal or vertical reference line. Unlike other marks, RuleMark has no data array.
Parameters:
yValue(number, optional): Draw a horizontal line at this y value.xValue(string | number, optional): Draw a vertical line at this x value.color(string, optional): Line color.lineWidth(number, optional): Stroke width.
SectorMark
Pie and donut charts.
Parameters:
data(SectorDataPoint[], required): Sector data withvalueandcategory.color(string, optional): Fill color (overrides automatic coloring).innerRadius(number, optional):0= pie chart, any value above0= donut chart. Values ≤ 1 are treated as a ratio of the max radius; values > 1 are treated as absolute dp.outerRadius(number, optional): Same behavior asinnerRadius.angularInset(number, optional): Gap between sectors in degrees.
Chart Props
The <VoltraAndroid.Chart> container accepts these props in addition to the standard style prop:
Grid Lines
Hide grid lines when you want the chart to feel more compact:
Multi-Series Charts
Add a series field to your data points when you want multiple datasets in the same chart. Use foregroundStyleScale to keep those series colors consistent:
Without foregroundStyleScale, colors are chosen automatically.
For side-by-side bars, set stacking="grouped":
Combining Marks
Mix mark types when one chart needs both context and emphasis, such as bars for totals plus a rule for a target:
Sparkline / Minimal Style
Hide axes for a clean, compact visualization:
Sizing
Chart dimensions are read from the style prop:
- Fixed size:
style={{ width: 300, height: 200 }} - Fill parent:
style={{ width: '100%', height: '100%' }}
If no width or height is specified, the chart defaults to 300×200 dp.
Platform Notes
legendVisibilityis not currently available on Android charts.- Point markers are circular on Android.
innerRadiusandouterRadiusonSectorMarkaccept either a ratio (0to1) or a larger fixed value.
