Chart
One chart component for dashboards — bar, horizontal bar, stacked bar, area, line, donut and sparkline — colored with tokens and readable by screen readers.
Overview
Chart draws the common dashboard charts from one data shape: category labels and one or more series. It is built on Recharts and colored with tokens, so tenant accents and dark mode apply without extra work.
Missing data stays missing: a null point is a gap in a line and an absent bar, never a zero. With no values at all, the chart shows an empty state instead of empty axes. Every chart is a named figure with a visually hidden table of the same numbers.
Recharts is a dependency of @unflowio/ui, so there is nothing extra to install. Because each component has its own entry point, it only ends up in your bundle on pages that import Chart.
Import
import { Chart } from '@unflowio/ui/components/Chart';Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | Required. Accessible name of the chart, also the caption of the hidden data table (e.g. "Spend this month") |
type | ChartType | — | Required. 'bar' | 'bar-horizontal' | 'stacked-bar' | 'area' | 'line' | 'donut' | 'sparkline' |
labels | string[] | — | Required. Category labels: one per data point (x axis), or one per slice for donut |
series | ChartSeries[] | — | Required. One entry per series. A null point is a gap, never zero. donut reads the first series only |
colors | ChartColor[] | chart-1 to chart-6 | Slice colors for donut, in label order |
height | number | 200 (160 donut, 40 sparkline) | Plot height in px |
legend | boolean | true with several series and for donut, never for sparkline | Shows the legend |
stacked | boolean | — | Stacks bar and area series. Always on for stacked-bar |
valueFormat | Intl.NumberFormatOptions | — | Formats values in tooltips, the hidden table and (in compact form) the axis, e.g. { style: 'currency', currency: 'EUR' } |
formatValue | (value: number) => string | — | Formats every value instead of valueFormat |
domain | [number, number] | 0 (or the lowest negative value) to a rounded maximum | Value axis range |
tooltip | boolean | true, never for sparkline | Shows a tooltip on hover |
loading | boolean | — | Shows a loading skeleton |
error | ReactNode | — | Rendered instead of the chart, e.g. an error StateMessage with a retry action |
emptyState | ReactNode | — | Rendered instead of the default StateMessage when no series has any value |
ChartSeries
| Field | Type | Description |
|---|---|---|
name | string | Required. Series name, shown in the legend, tooltip and table |
data | (number | null)[] | Required. One value per label. null is a gap |
color | ChartColor | Defaults to chart-1 to chart-6 by position, wrapping after six |
Colors
A ChartColor is one of:
| Value | Resolves to |
|---|---|
'chart-1' … 'chart-6' | The categorical chart palette (--chart-1 … --chart-6) |
'studio-language', 'studio-image', 'studio-video', 'studio-audio', 'studio-3d', 'studio-workflow' | The matching --studio-* color token |
'accent' | The tenant accent (--accent-primary) |
'fg' | Primary text color (--fg-primary) |
'muted' | A neutral grey (--border-default), for comparison or reference series |
'--my-color' or 'var(--my-color)' | Any CSS custom property |
'#0ea5e9', 'rgb(…)', … | Any CSS color |
Token colors are read from CSS variables at render, so a chart follows theme and accent changes.
Basic usage
| Category | October | September |
|---|---|---|
| Oct 1 | €12.00 | €10.00 |
| Oct 5 | €410.00 | €380.00 |
| Oct 9 | €760.00 | €700.00 |
| Oct 13 | €1,120.00 | €1,010.00 |
| Oct 17 | €1,480.00 | €1,390.00 |
| Oct 21 | €1,790.00 | €1,700.00 |
| Oct 26 | €2,184.60 | €2,010.00 |
<Chart
label="Spend this month"
type="area"
labels={['Oct 1', 'Oct 5', 'Oct 9', 'Oct 13', 'Oct 17', 'Oct 21', 'Oct 26']}
series={[
{ name: 'October', data: [12, 410, 760, 1120, 1480, 1790, 2184.6], color: 'accent' },
{ name: 'September', data: [10, 380, 700, 1010, 1390, 1700, 2010], color: 'muted' },
]}
valueFormat={{ style: 'currency', currency: 'EUR' }}
/>Bars
bar groups series side by side. bar-horizontal suits long category names, such as people or pages.
| Category | Predicted | Actual |
|---|---|---|
| Jul | €2,100.00 | €2,040.00 |
| Aug | €2,350.00 | €2,410.00 |
| Sep | €2,400.00 | €2,467.00 |
| Oct | €2,610.00 | €2,184.00 |
| Category | Projects |
|---|---|
| Ana Ferreira | 412 |
| Bruno Reis | 365 |
| Carla Dias | 298 |
| Diogo Matos | 214 |
<Chart
label="Predicted and actual spend"
type="bar"
labels={['Jul', 'Aug', 'Sep', 'Oct']}
series={[
{ name: 'Predicted', data: [2100, 2350, 2400, 2610], color: 'muted' },
{ name: 'Actual', data: [2040, 2410, 2467, 2184], color: 'fg' },
]}
valueFormat={{ style: 'currency', currency: 'EUR' }}
/>
<Chart
label="Top people by projects"
type="bar-horizontal"
labels={['Ana Ferreira', 'Bruno Reis', 'Carla Dias', 'Diogo Matos']}
series={[{ name: 'Projects', data: [412, 365, 298, 214] }]}
height={180}
/>Stacked
stacked-bar stacks every series. Set stacked to stack bar or area series too. Without color, series take chart-1 to chart-6 in order.
| Category | Web | Mobile | API | |
|---|---|---|---|---|
| Mon | 820 | 240 | 120 | 60 |
| Tue | 910 | 260 | 140 | 70 |
| Wed | 880 | 300 | 160 | 65 |
| Thu | 940 | 280 | 150 | 80 |
| Fri | 860 | 310 | 170 | 75 |
| Sat | 210 | 90 | 40 | 20 |
| Sun | 180 | 70 | 30 | 15 |
<Chart
label="Runs by channel"
type="stacked-bar"
labels={['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']}
series={[
{ name: 'Web', data: [820, 910, 880, 940, 860, 210, 180] },
{ name: 'Mobile', data: [240, 260, 300, 280, 310, 90, 70] },
{ name: 'API', data: [120, 140, 160, 150, 170, 40, 30] },
{ name: 'Email', data: [60, 70, 65, 80, 75, 20, 15] },
]}
/>Gaps
A null point breaks the line instead of dropping it to zero. The hidden table lists it as "No data".
| Category | Runs |
|---|---|
| Mon | 32 |
| Tue | 41 |
| Wed | No data |
| Thu | No data |
| Fri | 38 |
| Sat | 12 |
| Sun | 9 |
<Chart
label="Daily runs"
type="line"
labels={['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']}
series={[{ name: 'Runs', data: [32, 41, null, null, 38, 12, 9] }]}
/>Donut
donut reads the first series, with one value per label. Slice colors default to chart-1 to chart-6; pass colors to set them in label order.
| Category | Runs |
|---|---|
| Web | 5,240 |
| Mobile | 1,550 |
| API | 810 |
| 385 |
<Chart
label="Runs by channel"
type="donut"
labels={['Web', 'Mobile', 'API', 'Email']}
series={[{ name: 'Runs', data: [5240, 1550, 810, 385] }]}
/>Sparkline
sparkline is a 40 px trend line for tiles and table cells, with no axes, legend or tooltip. It fills the width of its container.
| Category | Runs |
|---|---|
| Day 1 | 8 |
| Day 2 | 11 |
| Day 3 | 9 |
| Day 4 | 14 |
| Day 5 | 13 |
| Day 6 | 16 |
| Day 7 | 12 |
| Day 8 | 18 |
| Day 9 | 17 |
| Day 10 | 21 |
| Day 11 | 19 |
| Day 12 | 24 |
| Day 13 | 22 |
| Day 14 | 26 |
<div className="w-40">
<Chart
label="Runs, last 14 days"
type="sparkline"
labels={days}
series={[{ name: 'Runs', data: [8, 11, 9, 14, 13, 16, 12, 18, 17, 21, 19, 24, 22, 26] }]}
/>
</div>Empty, loading and error
When every point is null, the chart shows an empty StateMessage ("No data yet"); pass emptyState to replace it. loading shows a skeleton at the chart's height, and error replaces the chart with whatever you pass.
No data yet
<Chart label="Daily runs" type="bar" labels={labels} series={[{ name: 'Runs', data: [null, null, null] }]} />
<Chart label="Daily runs" type="bar" labels={labels} series={series} loading />
<Chart
label="Daily runs"
type="bar"
labels={labels}
series={series}
error={<StateMessage type="error" title="Couldn't load runs" />}
/>Accessibility
- Renders a
figurenamed bylabel, so screen readers announce what the chart shows. - A visually hidden table holds the same numbers, captioned with
labeland formatted withvalueFormatorformatValuein the active locale. Missing points read "No data", never zero. - Don't rely on color alone: name series clearly, and keep the legend on when a chart has several series.
- Animations respect
prefers-reduced-motion.