Extra
BarChart
A FormaUI bar chart — vertical bars with rounded top corners, drawn with pure Compose Canvas (no chart-library dependency); gridlines, category labels, value labels, and a one-shot entry animation are all built in.
dev.formaui.components.chart
Preview
This toggle is site chrome only — the preview has its own light/dark switch inside.
Live preview
Live preview — ~37 MB development build
Usage
FormaBarChart(
entries = listOf(
FormaChartEntry("Jan", 12f),
FormaChartEntry("Feb", 32f),
FormaChartEntry("Mar", 21f),
),
showValueLabels = true,
)FormaBarChart
Vertical rounded bars scaled against a "nice" auto-computed (or explicit) y-axis maximum, with optional gridlines, category labels, value labels, and an entry animation; exposes an auto-generated data summary as its content description.
Supporting API
- FormaChartEntrydata class
- One data point shared by all FormaUI charts (label, value, optional explicit color). Charts are stateless and redraw when the caller passes a structurally different list — an equal-but-new list never replays the entry animation.
- FormaChartDefaultsobject
- Defaults shared by all FormaUI charts: MinChartHeight (180dp), MinDonutSize (160dp), DonutStrokeWidth (24dp), LineStrokeWidth (2dp), LinePointRadius (3dp), BarCornerRadius (4dp), LegendSwatchSize (12dp), GridLineCount (4), seriesColors (a six-color M3 palette with error last), gridLineColor, valueLabelStyle (tabular figures), axisLabelStyle, ValueFormatter, and EntryAnimationSpec (an 800ms tween).
- FormaChartLegendcomposable
- A wrapping row of color swatches and labels, one item per FormaChartEntry. Charts never embed a legend — place one next to the chart with the same entries (and, for a donut, the same palette) so swatches resolve to the chart's colors; an optional valueFormatter appends each entry's formatted value. Labels are real Text, so the legend is natively accessible.
Accessibility
Exposes an auto-generated data summary (e.g. "Bar chart with 3 categories. Jan: 12. …") as its semantics content description — override with contentDescription; empty entries describe themselves as "Bar chart with no data".