Chart
Bar, line, area and donut charts in plain SVG and CSS, no charting library: bars grow from the baseline one after another, lines draw themselves, rings sweep round, and every change of data tweens on a spring. The tooltip glides with rolling numbers, the legend folds series away, and the arrow keys walk the points.
See it as an AI agent does.See this component the way an AI agent does.
Installation
npx shadcn@latest add @keyframery/chartThis adds components/keyframery/chart.tsx and its primitive to your project, and installs UI SDK. The motion tokens are added to your global CSS the first time you install a component.
Usage
import { Chart, type ChartConfig } from "@/components/keyframery/chart"
const data = [
{ month: "Jan", visitors: 1840 },
{ month: "Feb", visitors: 2120 },
{ month: "Mar", visitors: 1980 },
]
const config = { visitors: { label: "Visitors" } } satisfies ChartConfig
export default function Usage() {
return <Chart aria-label="Visitors" data={data} config={config} categoryKey="month" />
}Examples
Bar chart
Rows of data and a config naming each series, as in shadcn's charts. Colours come from --chart-1 to --chart-5 in config order; bars grow from the baseline and the tooltip follows the pointer or the arrow keys.
Line chart
type="line" draws each series from the left. curve="linear" joins the points straight, and dots marks every one.
Stacked areas
type="area" with stacked piles each series on the one below. The fill fades down from the line in the series' colour.
Donut
For a ring, each row is a slice: categoryKey names it and the one numeric key is its value. Label the slices in the config; the hole shows the total, or the slice under the pointer.
Horizontal bars
orientation="horizontal" lays the bars down, categories down the side. Good for long names; set your own colour per series in the config.
Interactive legend and readout
Compose the parts yourself to place them. onActiveIndexChange reports the point under the pointer or the arrow keys, and hiddenSeries with onHiddenSeriesChange lets the legend switch series off: they fold into the baseline while the others take their room.
Stacked bars
stacked puts each series on the one before it, in config order. On arrival every stack builds up from the baseline, segment by segment; the tooltip adds the total, and switching a series off in the legend re-stacks the rest.
Motion
| Move | What you see |
|---|---|
| Cascade | Bars grow from the baseline one after another, left to right; a ring's slices sweep round from the top, and the others fade back from the slice under the pointer. |
| Draw | Lines draw themselves from the left, with their area unrolling under them, and their dots pop in after. |
| Spring | New data, stacking or hidden series tween every bar, line, slice, tick and grid line to its new place, with a small overshoot. |
| Glide | The cursor band or hairline, the tooltip and each line's dot travel to the active point, and the tooltip swings to the other side near the edge. |
| Roll | The tooltip's values, the axis ticks and a donut's total roll to each new number. |
| Stack | Stacked bars build up from the baseline, each segment growing once the one under it has; the tooltip ends with the stack's total. |
| Height | A series switched off in the legend folds into its baseline while the others widen into its room. |
| Press | Legend items sink a little and pop back. |
Timing and springiness follow the motion style you set. To change how fast this chart moves, pass speed:
<Chart speed="fast">
…
</Chart>"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.
Theming
Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.
| Variable | What it changes | Default |
|---|---|---|
--chart-1 | The series palette, --chart-1 to --chart-5 in config order (theme tokens a preset sets) | cobalt, sky, slate, amber, mist |
--chart-height | The chart's height, legend and axes included | 16rem |
--chart-grid | Grid rules (75% on all but the zero line) | --border |
--chart-axis | Axis labels | --muted-foreground |
--chart-cursor | The band or hairline on the active point | --foreground at 5% (band) or 22% (hairline) |
--chart-tooltip | Tooltip surface | --popover |
--chart-radius | Bar corners | --radius less 6px |
--chart-stroke | Line width | 2px |
--chart-dot | Dot size | 8px |
--chart-bar-gap | Space between bars in a group (never more than a third of a bar) | 4px |
API reference
Every part takes className and children, along with the props of the element it renders. The parts are rendered by UI SDK, so they also take render, to draw your own element, and a function of their state for className and style.
Chart
Renders a <element>, and takes its props too.
Prop
Type
ChartLegend
Renders a <div>, and takes its props too.
Prop
Type
ChartTooltip
Renders a <div>, and takes its props too.
Prop
Type
ChartContainer
Renders a <element>, and takes its props too.
Prop
Type
ChartTick
Renders a <div>, and takes its props too.
Prop
Type
Roll
Prop
Type
Other parts
These take the props of the element they render, and nothing else:
ChartCenter: a<div>ChartCursor: a<div>ChartGrid: a<div>ChartMarks: a<div>ChartPlot: a<div>ChartXAxis: a<div>ChartYAxis: a<div>ChartAreaChartBar: a<div>ChartDot: a<div>ChartGridLine: a<div>ChartLegendItem: a<button>ChartLineChartMarker: a<div>ChartPoint: a<div>ChartPoints: a<div>ChartSliceChartTable: a<table>ChartTooltipItem: a<div>ChartTooltipLabel: a<div>ChartTooltipTotal: a<div>
Keyboard
| Key | What it does |
|---|---|
| Tab | Moves focus to the legend's toggles, then to the chart's points as one tab stop. |
| ArrowRight | Moves to the next point and shows its values (Down for horizontal bars). |
| ArrowLeft | Moves to the previous point (Up for horizontal bars). |
| Home | Moves to the first point. |
| End | Moves to the last point. |
| Escape | Hides the tooltip; any arrow brings it back. |
| Space | Switches the focused legend series off or on. |
Accessibility
Roles, keyboard and focus are declared on the component's UI SDK primitive, and state is announced through the matching ARIA attributes. More in Accessibility.
Built on UI SDK's core
UI SDK doesn't ship a chart, so this one is defined with its core: one definePrimitive in components/keyframery/core/chart-core.ts, with no React in it. UI SDK's adapters can render that same definition in Vue, Svelte, Solid and web components. To keep your own styling and take only the motion, import from @/components/keyframery/primitives/chart.
Questions
How does the animated Chart for UI SDK move?
Cascade: Bars grow from the baseline one after another, left to right; a ring's slices sweep round from the top, and the others fade back from the slice under the pointer. Draw: Lines draw themselves from the left, with their area unrolling under them, and their dots pop in after. Spring: New data, stacking or hidden series tween every bar, line, slice, tick and grid line to its new place, with a small overshoot. Glide: The cursor band or hairline, the tooltip and each line's dot travel to the active point, and the tooltip swings to the other side near the edge. Roll: The tooltip's values, the axis ticks and a donut's total roll to each new number. Stack: Stacked bars build up from the baseline, each segment growing once the one under it has; the tooltip ends with the stack's total. Height: A series switched off in the legend folds into its baseline while the others widen into its room. Press: Legend items sink a little and pop back.
Do I need Motion or Framer Motion for the animated Chart?
No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.
UI SDK has no chart. How is this one built on UI SDK?
Its behaviour is one definition written with UI SDK's core (definePrimitive), in components/keyframery/core/chart-core.ts. Its parts are rendered by UI SDK's adapter, so they take render, state-based class names and data-slot, like every UI SDK component.
What happens to the Chart when someone turns on reduced motion?
Nothing moves. State changes happen at once, or with a short fade.
More in Data
All componentsImage Cropper
The selection springs to a new ratio, handles grow while you drag and the zoom settles on a spring.
Data table
The full list screen on top of Table, with no table library: give it data and columns and it owns the search, faceted filters with live counts, the sort, hidden columns, row selection, the page and the page size, each one controlled or not so a page can keep it in the URL. Rows cascade in after a sort or a page turn, a hidden column folds away while the others close the gap, Reset slides in while anything is filtered, and a bulk bar rises from the bottom centre while rows are selected.