Scatter chart
Points on two value axes, to show how two measures move together: deal size against days to close, price against rating. A third value can set each mark's area, and a trend line can summarise each series. For one measure over time, use the line chart.
Install
npx shadcn@latest add @thrum-pro/scatter-chartThis is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.
Data shape
type ScatterChartPoint = {
x: number | null; // null = not drawn, kept in the table
y: number | null;
size?: number | null; // drawn as the mark's area
label?: string; // shown in the readout
};[
{ x: 12, y: 4200, size: 18, label: "Acme" },
{ x: 34, y: 18500, size: 42, label: "Northwind" },
{ x: 21, y: null, label: "Globex" },
]Props
| Prop | Type | Default | Description |
|---|---|---|---|
series | readonly ScatterChartSeries[] | Required | Up to five series of { key, name, points, color? }. Each gets its own colour and its own shape: circle, square, triangle, diamond, then a triangle pointing down. |
label | string | Required | What the chart shows. Read by screen readers and used as the table caption. |
xLabel | string | – | Name of the horizontal axis. Shown under it at the right, and in the readout. Without it the readout says “x”. |
yLabel | string | – | Name of the vertical axis. Shown above it at the left, and in the readout. Without it the readout says “y”. |
sizeLabel | string | Default "Size" | Name of the size value in the readout and the table. |
xFormat | Intl.NumberFormatOptions | Default compact | How horizontal values are written. |
format | Intl.NumberFormatOptions | Default compact | How vertical values are written. |
sizeFormat | Intl.NumberFormatOptions | Default compact | How sizes are written. |
locale | string | Default "en-US" | Locale for number formatting. |
trendLine | boolean | Default false | Draw a dashed least-squares line through each series that has two or more points with different x values. |
legend | boolean | Default true | Show the legend with each series' shape. It appears when there are two or more series. |
onActiveChange | (index: number | null) => void | – | Called with the index of the point under the cursor, counted left to right over all series, or null when the cursor leaves. |
sound | boolean | Default true | Play a tick as the cursor moves between points, if the visitor has sound on. |
emptyLabel | string | Default "No data" | Text shown when there is nothing to draw. |
className | string | – | Sets the size. The default is full width and 256 pixels tall, legend included. |
Motion and sound
Motion
- First draw: the marks grow from their centres in 250 ms, left to right, and the whole entrance takes 550 ms at most.
- New data with the same number of points: each mark and trend line moves to its new place in 400 ms with no overshoot. A different number of points is drawn again at once.
- The cursor ring and the readout follow the pointer on a stiff spring.
- Reduced motion: the chart appears complete, and data changes and the cursor move instantly.
Sound
- A soft tick each time the cursor lands on a different point, at most one every 40 ms.
Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works
Accessibility
- The chart is one tab stop, exposed as a slider whose value text is the point under the cursor, for example “Acme, Inbound: Days to close 12, Deal size $4.2K”.
- A visually hidden table carries every point of every series, including points with a missing value that are not drawn.
- Series differ in mark shape as well as colour, and the legend shows both. Marks are at least 8 px across, and size is drawn as area, so a value twice as large covers twice the ink.
- Every mark has a 2 px ring of the background, so overlapping marks stay apart. The whole plot is the pointer target: the pointer reads the nearest point.
- The readout is a floating surface. Under frosted glass it turns translucent and keeps its text at 4.5:1.
| Keys | Action |
|---|---|
| Tab | Focus the chart. The cursor goes to the right-most point. |
| ← → | Move to the next point to the left or right, over all series. |
| Home / End | Jump to the left-most or right-most point. |
| Esc | Hide the cursor. |
Source
The source comes with Pro
TypeScript source · Copy-paste ready · MIT-compatible for client projects · Includes all dependencies
Files and dependencies
- Adds
components/ui/scatter-chart.tsx- Packages
motion- Brings along
- Chart foundationsMotion tokensSound engineChart tooltip
Changelog
- 1.0.0 · 2026-12-03First release.