Dashboard chart that compares: bars rise as pills, lines trace once, and scrubbing pulls a ring onto the previous period, the gap drawn as a green or red pill.
Move your pointerTouch and move
Revenue by plan
€14,400€1012345678940123456789,401234567890012345678900123456789€99,999up24.1%2012345678940123456789.10123456789%99.9%vs last year
Last year€11,600€1012345678910123456789,601234567890012345678900123456789€9,800
Last year
Monthly revenue by plan against last year
period
Team
Business
Last year
Nov
€6,200
€2,400
€7,100
Dec
€6,600
€2,600
€7,600
Jan
€6,400
€2,900
€7,600
Feb
€7,100
€3,100
€8,100
Mar
€7,600
€3,000
€8,600
Apr
€7,400
€3,500
€8,800
May
€8,100
€3,800
€9,400
Jun
€8,400
€3,700
€9,600
Jul
€8,900
€4,200
€13,500
Aug
€8,600
€4,500
€10,000
Sep
€9,300
€4,400
€10,900
Oct
€9,800
€4,600
€11,600
chart · , lively
chart-demo.tsx
When to use
Use it as the main chart of a dashboard card when the question is compared with what. Pass compare data and scrubbing shows both values and the gap; the legend isolates series.
The real chart of a dashboard, built for the question a dashboard is asked first: compared with
what? Revenue against the same month last year, tickets solved against last week. Pass compare
and the previous period is drawn as a ghost (a cap on each bar, a dashed line under a line or an
area). Scrub the plot and a hollow ring grows out of the readout ball and rides to last period's
value; the 4 px pill joining them is the difference, green when you are ahead and red when you
are behind, so a widening gap is felt before it is read. The tooltip names both values and the
change, and onCompareChange feeds a ChartDelta headline that rolls as you scrub.
Bars stand up as pills in a cascade (stacks are nested pills, bottom first), lines trace
themselves once, and a legend pill stretches onto the series it isolates. A donut preset covers
shares of a whole.
Without children, preset renders the default composition: grid, both axes, the layer, a legend
when there is more than one series (or a comparison), and the tooltip. Four presets:
bar (default): grouped or stacked standing pills, a 20% gap in each band, negative values hang
below the baseline.
line: 2 px strokes with round joins; the ball is the point. dashed: true on a series draws
a target.
area: a line over a gradient fill that fades to the baseline (between curves when
stacked); the drawn edge leads the fill.
donut: a 16 px ring of round-capped segments with 3° gaps, one per row, the total (or the
segment under the pointer, the keyboard or the legend) rolling in the centre. No comparison.
Bars carry a top highlight, areas a gradient and lines a soft shadow tinted by their color, in
both themes; flat turns them off.
compare="previous" reads each row's predecessor (month over month); an array is a parallel
dataset in the same order (last year, last week). The first row of "previous" has no ghost.
compareOf picks what is compared: the stack total by default for stacked bars and areas,
otherwise the first series. Isolating a series from the legend hides the ghost of the total.
compareLabel names the previous period in the legend key, the tooltip row and the table.
onCompareChange reports { index, value, previous, delta } for the point under the readout
(the anchor at rest). delta is a ratio, null when the previous value is 0.
ChartDelta is the headline pill: value is that ratio, its triangle turns over with the
sign and the digits roll.
import { Chart, type ChartComparison, ChartDelta } from "@/components/ui/chart"const [cmp, setCmp] = useState<ChartComparison | null>(null)<ChartDelta value={cmp?.delta} label="vs last year" /><Chart data={data} x="month" series={series} compare={lastYear} onCompareChange={setCmp} />
Compose parts to mix layers, for example bars with a dashed target line:
Everything is controlled or uncontrolled: value / onValueChange (the active row, so a card
headline can follow it with its own Roll), activeSeries / onActiveSeriesChange (legend
isolation). brush is the row range in view: drive it from a period control and the domain
retargets on a calm spring. Series colors take a token
name (chart-3) or any CSS color; by default they read chart-1..5 from your theme. Themes
without them get five hues 72° apart around your primary at matched lightness, so neighbours in
a stack are always clearly distinct, in both themes. Data changes are diffed by the x value:
existing marks move on a calm spring, new ones rise, removed ones fold to the baseline.
ChartTooltip render replaces the tile's content; ChartReadout is the ball itself, for custom
content. temperament tunes motion intensity only: at calm bars rise without overshoot and the
ball glides without the stop squash.
A helpdesk card: tickets solved this week over last week's dashed ghost. Scrub to Wednesday and
the pill turns red: last week's backlog push was bigger.
Move your pointerTouch and move
Tickets solved
Support queue, this week
down6.3%60123456789.30123456789%99.9%vs last Sun
Sundown6.3%60123456789.30123456789%99.9%
Solved747012345678940123456789231
Last week797012345678990123456789231
Last week
Tickets solved per day against last week
day
Solved
Last week
Mon
182
168
Tue
205
190
Wed
196
214
Thu
231
205
Fri
214
198
Sat
96
88
Sun
74
79
chart · , lively
chart-line-demo.tsx
Weekly active users by channel, stacked areas with their gradient:
Stock by warehouse as a donut; point at a warehouse in the legend and its segment takes the
centre.
Move your pointerTouch and move
Stock by warehouse
Units on hand, all SKUs
North hubHarborEast yardAirportTotal11,9201012345678910123456789,90123456789201234567890012345678911,920
Units in stock by warehouse
warehouse
Units
North hub
4,820
Harbor
3,160
East yard
2,410
Airport
1,530
chart · , lively
chart-donut-demo.tsx
Loading, error and empty states in report widgets: the axes stay, placeholder pills stand while
data loads, the error rises with a Retry, and an empty period keeps a hollow ball at the baseline.
The root is a group named by aria-label. The plot <svg> is role="img" with a generated
summary ("Team and Business, 12 points, bar chart. Team last €9,800, highest €9,800 in Oct."),
refreshed when the data changes.
Every value is also in a visually hidden table, with a column for the previous period (opt out
with table={false}); marks, ticks, balls, the ring and the tooltip tile are aria-hidden.
One focusable role="slider" covers the plot; its aria-valuetext reads the point ("Mar:
Team €7,600, Business €3,000, Last year €8,600, up 23.3%"). A polite status region announces the point,
debounced by 300 ms so arrowing does not chatter. The focus halo (ring-[3px] ring-ring/50)
is drawn around the ball (around the whole donut, which has no ball).
Legend items are button[aria-pressed], 32 px tall. Faded series keep 25% opacity and their
legend labels keep foreground (AA). The comparison key in the legend is plain text, not a
button.
Colors never carry meaning alone: legend labels, tooltip text and the table name every series;
patterns adds diagonal hatching to every series after the first. The delta's direction is a
triangle that turns over and the words "up" / "down" for screen readers, not only green and red;
its digits stay foreground.
No entrance: bars, lines, areas and the donut are drawn at their final shape on mount. The ball, the
tooltip and the legend pill fade between positions instead of springing; the comparison ring and
its delta pill appear in place and fade, without growing out of the ball, and changed digits
crossfade. The still frame is a finished chart with its legend and the anchor
readout.
Own SVG and scales (linear, band, time), no chart library. The entrance runs once when the chart
enters the viewport (IntersectionObserver); the width comes from one ResizeObserver. Bars
animate their height on the entrance and on data changes (up to 60 bars; denser charts crossfade),
so rounded tops never distort; lines and areas reveal through a clip, the ball and the tooltip move
on transform only, and nothing runs once they settle. The ring and the delta pill read the ball's
spring, so the comparison adds no animation loop of its own. Dependencies: motion (peer) and the shared ball, pill, roll and beats
helpers.
This version makes comparison first-class (compare, ChartDelta). To stay within the size
budget, ChartBrush with defaultBrush / onBrushChange was removed (brush stays as the
controlled range in view, for a period control), and the donut no longer has a readout ball on the
ring: the segment under focus brightens and its value takes the centre.
Technical sheet
Motion
calm
260 ms · bounce 0
lively
400 ms · bounce 0.3
playful
540 ms · bounce 0.45
Main spring of each temperament. Set it with the temperament prop or MotionKitProvider; the default is lively.
Size
Not measured yet · budget 15.1 kB gzip
Component and MotionKit helpers; excludes react, react-dom, motion.
Dependencies
motion · peer
Triggers
pointer movement, entering the viewport, a value change
Reduced motion
No rise or trace: marks are drawn at mount; the ball, tooltip and legend pill fade between positions, the comparison ring and delta pill fade in place without sliding, and digits crossfade.
Keyboard
Tab
Focuses the plot (the ball shows a focus halo), then the legend items
ArrowLeft / ArrowRight
Moves the readout to the previous or next point; with compare, the ring and the delta follow
ArrowDown / ArrowUp
Same as ArrowLeft / ArrowRight
PageDown / PageUp
Moves the readout five points
Home / End
Moves the readout to the first or last point in view
Escape
Clears the active point; the ball returns to its anchor
Enter / Space
On a legend item: isolates its series, again to release
Browsers
Last 2 versions of Chrome, Edge, Firefox and Safari (iOS 16.4+)