Skip to content

Chart

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
Used for
  • Runs per day
  • Latency percentiles
  • Spend over time
  • Events by action
  • Inline trends

Examples

Type

Share of the whole

Latency, with units

Drill into a bar

Sparkline

Donut and pie

Period

Rounded and partial slices

Rings

Day

Empty state

Morph between kindsProPro

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 chart
For Claude Code, Cursor or Codex: installs it and wires the props to your own data.

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
Defaultfalse
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
Default0.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
Defaultfalse
Bars and areas. Values are summed from zero, so keep them non-negative.
smooth
boolean
Defaultfalse
Monotone curve that never overshoots a peak.
legend
boolean
Defaultmore than one series
Buttons that toggle each series. The last visible series stays on.
format / formatX
(v: number) => string / (x: string) => string
Defaultcompact / identity
Axis and tooltip text, for units or dates.
domain
[number, number]
Defaultdata range
Bars and areas always include zero.
height
number
Default240
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
Defaultnull
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
Defaultfalse
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
Defaultfalse
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]
Defaultformat / 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
Defaultfalse
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
Defaultfalse
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
Defaultfalse
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.

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

  1. 01Draws line, bar, area, donut, pie and rings charts in plain SVG with no chart library, sized to the width it is given.
  2. 02Colours each series from the theme chart colours, with one accent and quiet neutrals, in light and dark.
  3. 03Reads a point by keyboard: arrow keys move the tooltip, Enter or Space selects it, and a legend button hides a series.
  4. 04Shows what changed after a data update: bars slide from their old box to the new one, new bars fade in, lines tween.
  5. 05Shows an empty state instead of an empty frame, and formats axis and tooltip values with the functions you pass.
  6. 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

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" }).

Need help?

Stuck on Chart, or found something off? We read every message.