Line, bar, area, donut, pie, rings and sparkline in plain SVG, no chart library. One accent plus quiet neutrals, a tooltip you can reach with the arrow keys, legend buttons that toggle series, an empty state and a hidden data table for screen readers. Sparkline renders on the server; Chart hydrates to measure its width.
On this page
- Runs per day
- Latency percentiles
- Spend over time
- Events by action
- Inline trends
Examples
Share of the whole
Latency, with units
Drill into a bar
Sparkline
Donut and pie
Rounded and partial slices
Rings
Empty state
Morph between kindsPro
Chart Morph draws bars, a line and an area from one set of marks. Switching kind morphs them: bars shrink to points on their values, then a line draws through the points, and Area lets the fill rise under it; going back plays the same steps in reverse. A new measure eases every value and the axis instead of redrawing. The tooltip and the arrow keys keep working while it moves, and reduced motion switches at once.
Installation is part of Pro
Pro components install from a licensed registry. The live preview stays open to everyone.
Installation
npx knowns-ui@latest add chartPaste this into your coding agent (Claude Code, Cursor, Codex). It checks your project, sets up the registry, runs the install and verifies it.
Install Chart from Knowns UI into this project. Work step by step, show me each change, and ask before you edit files outside this project.
Context: Knowns UI (https://ui.knowns.dev) is a shadcn registry. Items land in the project as source files. Docs: https://ui.knowns.dev/docs/chart
1. Check the project first. Stop and tell me if any of these is missing:
- React 19 and Tailwind CSS v4.
- A components.json at the project root. If there is none, ask me before running `npx knowns-ui@latest init --no-key` (it runs shadcn init when needed, then adds the registries).
2. Run:
```bash
npx knowns-ui@latest add chart
```
It writes these files:
- lib/knowns/run.ts
- lib/knowns/json.tsx
- lib/knowns/status.ts
- lib/knowns/tone.ts
- lib/knowns/types.ts
- lib/knowns/use-abortable.ts
- lib/knowns/utils.ts
- lib/knowns/motion.tsx
- lib/knowns/motion-utils.ts
- components/ui/knowns/animated-number.tsx
- components/ui/knowns/chart/chart.tsx
- components/ui/knowns/chart/chart-utils.ts
- components/ui/knowns/chart/sparkline.tsx
- components/ui/knowns/chart/chart-radial.tsx
and installs these npm packages: clsx@^2.1.1, tailwind-merge@^3.7.0.
3. While it runs:
- It also adds a few @keyframes (all named kn-*) to the global CSS file (globals.css or the file components.json points at). Let it: they only add animations.
- If it asks to overwrite files under lib/knowns/: these are shared by every Knowns UI item. List them, say whether I changed them (check git), and ask me before you answer.
- If it asks to overwrite any other file, show me the diff and ask me.
4. Verify:
- Every file in the list above exists.
- The project type-checks (for example `npx tsc --noEmit`) and the dev build has no new errors.
5. Use it: follow the examples and props on https://ui.knowns.dev/docs/chart, and ask me if anything about my data is unclear.
If the Knowns UI MCP server is connected (https://ui.knowns.dev/docs/ai-and-mcp), use get_component({ name: "chart" }) or search_docs for details.
Finish with a short summary: the files you added or changed, the packages you installed, and anything I still need to do.Props
- type
"line"|"bar"|"area"|"donut"|"pie"|"rings"- Default
"line" - Bars group side by side unless stacked. Donut and pie make one slice per row of data, sized by the first series. Rings make one ring per row, the first outermost.
- goalKey
string- Default
"goal" - Rings. The field with each ring's goal. Progress is value over goal; past it the arc laps the start, up to three laps, with a soft shadow on its end. Rings: thickness is the share of the radius the rings fill (0.62, each ring at most 14px wide), center="total" is the overall progress, gap defaults to 3. focused and onFocusChange let you drive the focus from outside, tooltip={false} hides the tooltip, and VIVID_COLORS is a bolder set for barColors.
- rounded
boolean- Default
false - Donut: round the ends of every slice (half circles as wide as the ring). The gap between slices is kept; a single full ring has no ends.
- maxKey
string- Donut and pie: the field that holds each slice's max. The slice's arc follows its max and the first series' value fills that share over a faint track in the same colour; center="total" sums the values. Without it, slices are sized by value.
- thickness / center / centerLabel / gap
number / "total"|ReactNode / string / number- Default
0.32 / none / "Total" / 2 - Donut and pie. Thickness is the ring width as a share of the radius; a pie has no hole. center="total" rolls the sum of the visible slices in the hole, or pass your own node. Gap is the space between slices in px.
- data / x
Record<string, string | number | null>[] / string- One object per category. A null value leaves a gap in lines and no bar.
- series
{ key, label, color? }[]- Up to five read well. Colours default to --chart-1..5: one accent, two neutrals, green, amber, red. Override per series with any CSS colour.
- label
string- Required. Names the chart for screen readers and captions the data table.
- stacked
boolean- Default
false - Bars and areas. Values are summed from zero, so keep them non-negative.
- smooth
boolean- Default
false - Monotone curve that never overshoots a peak.
- legend
boolean- Default
more than one series - Buttons that toggle each series. The last visible series stays on.
- format / formatX
(v: number) => string / (x: string) => string- Default
compact / identity - Axis and tooltip text, for units or dates.
- domain
[number, number]- Default
data range - Bars and areas always include zero.
- height
number- Default
240 - Plot height in px. Width follows the container.
- onSelect
(index: number, datum) => void- Makes points selectable: fired on a click, and on Enter or Space for the point the arrow keys are on.
- selected / defaultSelected
number|null- Default
null - The selected point. Pass selected to control it from onSelect, or defaultSelected to let the chart keep it. The point is dimmed in, ringed on lines, and named in the chart's label and live region.
- endDot
boolean- Default
false - Lines and areas: a dot on the last point of each line. It glides with the line when the data changes.
- slots
number- Lines and areas: a fixed number of x slots. Points fill from the left, so a new point extends the line to the right while the old points stay put and the end dot glides; a shorter list (a restart) cross-fades in 120 ms.
- fadeArea
boolean- Default
false - Areas of one series: a vertical gradient from about 14% of the line colour to nothing at the baseline, instead of a flat tint.
- series.axis
"left"|"right"- Default
"left" - Lines: read a series against the right-hand axis. It gets its own scale (and tick labels at the right edge), so runs per minute and latency in ms can share a plot. Ignored on bars and stacked areas.
- formatRight / domainRight
(v) => string / [min, max]- Default
format / data range - Format and fixed range for the right-hand axis. formatRight also formats the tooltip, end label and table values of series on it.
- series.dashed
boolean- Default
false - Lines: draw the series dashed, for a threshold, a target or a second kind of measure.
- annotations
{ x, label, tooltip?, showLabel? }[]- Lines and areas: a dashed vertical line at the category x (the value of your x field) with a small button on it. Hover or focus opens a tooltip with the label and tooltip; the button is named by the label. showLabel also writes the label in small mono type beside the button, on the side with more room. Unknown x values are skipped.
- endLabels / series.icon
boolean / ReactNode- Default
false - Lines and areas: each series' latest value at its line end, after its icon. The value rolls (Animated Number) and the label follows the line when it glides; labels that would overlap move apart.
- focusSeries
boolean- Default
false - Hovering an end label or a legend entry dims the other series to 20% in 120 ms. Off by default.
- empty
ReactNode- Default
"No data yet" - Shown in place of the plot when no series has a value.
- Sparkline
{ values, label, area?, smooth?, endDot?, color?, width?, height? }- A line with no axes for tiles and table cells. Needs only values and a label, and renders on the server.
| Prop | Type | Default | Description |
|---|---|---|---|
| type | "line" | "bar" | "area" | "donut" | "pie" | "rings" | "line" | Bars group side by side unless stacked. Donut and pie make one slice per row of data, sized by the first series. Rings make one ring per row, the first outermost. |
| goalKey | string | "goal" | Rings. The field with each ring's goal. Progress is value over goal; past it the arc laps the start, up to three laps, with a soft shadow on its end. Rings: thickness is the share of the radius the rings fill (0.62, each ring at most 14px wide), center="total" is the overall progress, gap defaults to 3. focused and onFocusChange let you drive the focus from outside, tooltip={false} hides the tooltip, and VIVID_COLORS is a bolder set for barColors. |
| rounded | boolean | false | Donut: round the ends of every slice (half circles as wide as the ring). The gap between slices is kept; a single full ring has no ends. |
| maxKey | string | - | Donut and pie: the field that holds each slice's max. The slice's arc follows its max and the first series' value fills that share over a faint track in the same colour; center="total" sums the values. Without it, slices are sized by value. |
| thickness / center / centerLabel / gap | number / "total" | ReactNode / string / number | 0.32 / none / "Total" / 2 | Donut and pie. Thickness is the ring width as a share of the radius; a pie has no hole. center="total" rolls the sum of the visible slices in the hole, or pass your own node. Gap is the space between slices in px. |
| data / x | Record<string, string | number | null>[] / string | - | One object per category. A null value leaves a gap in lines and no bar. |
| series | { key, label, color? }[] | - | Up to five read well. Colours default to --chart-1..5: one accent, two neutrals, green, amber, red. Override per series with any CSS colour. |
| label | string | - | Required. Names the chart for screen readers and captions the data table. |
| stacked | boolean | false | Bars and areas. Values are summed from zero, so keep them non-negative. |
| smooth | boolean | false | Monotone curve that never overshoots a peak. |
| legend | boolean | more than one series | Buttons that toggle each series. The last visible series stays on. |
| format / formatX | (v: number) => string / (x: string) => string | compact / identity | Axis and tooltip text, for units or dates. |
| domain | [number, number] | data range | Bars and areas always include zero. |
| height | number | 240 | Plot height in px. Width follows the container. |
| onSelect | (index: number, datum) => void | - | Makes points selectable: fired on a click, and on Enter or Space for the point the arrow keys are on. |
| selected / defaultSelected | number | null | null | The selected point. Pass selected to control it from onSelect, or defaultSelected to let the chart keep it. The point is dimmed in, ringed on lines, and named in the chart's label and live region. |
| endDot | boolean | false | Lines and areas: a dot on the last point of each line. It glides with the line when the data changes. |
| slots | number | - | Lines and areas: a fixed number of x slots. Points fill from the left, so a new point extends the line to the right while the old points stay put and the end dot glides; a shorter list (a restart) cross-fades in 120 ms. |
| fadeArea | boolean | false | Areas of one series: a vertical gradient from about 14% of the line colour to nothing at the baseline, instead of a flat tint. |
| series.axis | "left" | "right" | "left" | Lines: read a series against the right-hand axis. It gets its own scale (and tick labels at the right edge), so runs per minute and latency in ms can share a plot. Ignored on bars and stacked areas. |
| formatRight / domainRight | (v) => string / [min, max] | format / data range | Format and fixed range for the right-hand axis. formatRight also formats the tooltip, end label and table values of series on it. |
| series.dashed | boolean | false | Lines: draw the series dashed, for a threshold, a target or a second kind of measure. |
| annotations | { x, label, tooltip?, showLabel? }[] | - | Lines and areas: a dashed vertical line at the category x (the value of your x field) with a small button on it. Hover or focus opens a tooltip with the label and tooltip; the button is named by the label. showLabel also writes the label in small mono type beside the button, on the side with more room. Unknown x values are skipped. |
| endLabels / series.icon | boolean / ReactNode | false | Lines and areas: each series' latest value at its line end, after its icon. The value rolls (Animated Number) and the label follows the line when it glides; labels that would overlap move apart. |
| focusSeries | boolean | false | Hovering an end label or a legend entry dims the other series to 20% in 120 ms. Off by default. |
| empty | ReactNode | "No data yet" | Shown in place of the plot when no series has a value. |
| Sparkline | { values, label, area?, smooth?, endDot?, color?, width?, height? } | - | A line with no axes for tiles and table cells. Needs only values and a label, and renders on the server. |
Keyboard: Tab to the plot, then Left and Right (or Home and End) step through the points and the tooltip follows; Escape clears it. With onSelect, Enter or Space selects the point. The same values sit in a visually hidden table after the chart. There is no intro: the chart first draws in its final state. When the data changes, bars move from their old size to the new one, new bars fade in, removed ones fade out, lines and the value axis ease to the new scale; reduced motion skips all of it. Colours come from the --chart-1..5 variables, so one override in your theme restyles every chart.
What it handles
- 01Draws line, bar, area, donut, pie and rings charts in plain SVG with no chart library, sized to the width it is given.
- 02Colours each series from the theme chart colours, with one accent and quiet neutrals, in light and dark.
- 03Reads a point by keyboard: arrow keys move the tooltip, Enter or Space selects it, and a legend button hides a series.
- 04Shows what changed after a data update: bars slide from their old box to the new one, new bars fade in, lines tween.
- 05Shows an empty state instead of an empty frame, and formats axis and tooltip values with the functions you pass.
- 06Keeps a hidden data table of every point for screen readers, and renders Sparkline on the server.
States
- First render
- Nothing. The chart paints its final state
- none
- Data change, bars
- Each bar moves from its old box to the new one
- 280ms, ease in-out
- Data change, lines and areas
- The points tween to their new values
- 280ms, ease in-out
- Bar added
- The new bar fades in
- 180ms, ease out
- Bar removed
- The bar fades out where it was
- 120ms, ease out
- Value labels
- Fade in once the bars have grown
- 120ms after a 280ms delay
- Hover or focus
- The tooltip fades in; legend and series dim by opacity
- 120ms, ease out
- Data change, donut and pie
- The slices' angles tween to their new values; a slice that comes back grows from its start
- 280ms, ease in-out
- Data change, rings
- Each arc sweeps from its old length to the new one, past the start when it laps
- 280ms, ease in-out
- Reduced motion
- Every change lands at once
- 0ms
| State | What moves | Timing |
|---|---|---|
| First render | Nothing. The chart paints its final state | none |
| Data change, bars | Each bar moves from its old box to the new one | 280ms, ease in-out |
| Data change, lines and areas | The points tween to their new values | 280ms, ease in-out |
| Bar added | The new bar fades in | 180ms, ease out |
| Bar removed | The bar fades out where it was | 120ms, ease out |
| Value labels | Fade in once the bars have grown | 120ms after a 280ms delay |
| Hover or focus | The tooltip fades in; legend and series dim by opacity | 120ms, ease out |
| Data change, donut and pie | The slices' angles tween to their new values; a slice that comes back grows from its start | 280ms, ease in-out |
| Data change, rings | Each arc sweeps from its old length to the new one, past the start when it laps | 280ms, ease in-out |
| Reduced motion | Every change lands at once | 0ms |
Works with
When to use
When to use
- A trend or comparison over time or categories: usage, latency, eval scores, spend.
- A tiny trend inside a stat tile or table cell (Sparkline).
- The split of a total into a few parts (donut or pie), or progress against goals as concentric rings.
When not to use
- Exact numbers per row: a table is easier to compare: use Data Table.
- Share of a limit or one value in one bar: use Progress.
- A donut that must match the Dither field look: use Dither Donut Chart.
Using with AI
Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:
- Add the Knowns UI Chart to my app and wire it to my own data.
- I need a trend or comparison over time or categories: usage, latency, eval scores, spend. Set that up with the Knowns UI Chart.
- Which Chart props do I need for a minimal setup? Show me a short example.
With the server connected, your assistant calls get_component({ name: "chart" }) and search_docs({ query: "chart" }).