UnflowUI
Components

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

PropTypeDefaultDescription
labelstring—Required. Accessible name of the chart, also the caption of the hidden data table (e.g. "Spend this month")
typeChartType—Required. 'bar' | 'bar-horizontal' | 'stacked-bar' | 'area' | 'line' | 'donut' | 'sparkline'
labelsstring[]—Required. Category labels: one per data point (x axis), or one per slice for donut
seriesChartSeries[]—Required. One entry per series. A null point is a gap, never zero. donut reads the first series only
colorsChartColor[]chart-1 to chart-6Slice colors for donut, in label order
heightnumber200 (160 donut, 40 sparkline)Plot height in px
legendbooleantrue with several series and for donut, never for sparklineShows the legend
stackedboolean—Stacks bar and area series. Always on for stacked-bar
valueFormatIntl.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 maximumValue axis range
tooltipbooleantrue, never for sparklineShows a tooltip on hover
loadingboolean—Shows a loading skeleton
errorReactNode—Rendered instead of the chart, e.g. an error StateMessage with a retry action
emptyStateReactNode—Rendered instead of the default StateMessage when no series has any value

ChartSeries

FieldTypeDescription
namestringRequired. Series name, shown in the legend, tooltip and table
data(number | null)[]Required. One value per label. null is a gap
colorChartColorDefaults to chart-1 to chart-6 by position, wrapping after six

Colors

A ChartColor is one of:

ValueResolves 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

Spend this month
CategoryOctoberSeptember
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.

Predicted and actual spend
CategoryPredictedActual
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
Top people by projects
CategoryProjects
Ana Ferreira412
Bruno Reis365
Carla Dias298
Diogo Matos214
<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.

Runs by channel
CategoryWebMobileAPIEmail
Mon82024012060
Tue91026014070
Wed88030016065
Thu94028015080
Fri86031017075
Sat210904020
Sun180703015
<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".

Daily runs
CategoryRuns
Mon32
Tue41
WedNo data
ThuNo data
Fri38
Sat12
Sun9
<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.

Runs by channel
CategoryRuns
Web5,240
Mobile1,550
API810
Email385
<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.

Runs, last 14 days
CategoryRuns
Day 18
Day 211
Day 39
Day 414
Day 513
Day 616
Day 712
Day 818
Day 917
Day 1021
Day 1119
Day 1224
Day 1322
Day 1426
<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 figure named by label, so screen readers announce what the chart shows.
  • A visually hidden table holds the same numbers, captioned with label and formatted with valueFormat or formatValue in 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.