How it works
The plot measures its own width with a ResizeObserver and draws the SVG at that size, so 12px ticks and round points never scale. Ticks are round numbers (1, 2, 2.5 or 5 times a power of ten) starting at zero. Points are a slightly lightened series colour with a ring in the surface colour, so dense clusters keep their edges, and they pop in on a spring with a small stagger. Pointing finds the nearest point within 28px: it grows, the other series fade, dashed guides run to both axes and a dark tooltip follows, flipping below near the top. The legend buttons toggle series, always leaving at least one.
Use it for
- Showing whether two measures move together, and how groups differ: time against pages, price against rating, size against duration.
Look elsewhere when
- Thousands of points: draw them on a canvas or bin them into a heatmap.
- Values over time: use a line chart.
Usage
import { ScatterChart } from './ScatterChart.jsx'
export function Engagement({ desktop, mobile }) {
return (
<ScatterChart
title="Engagement by device"
label="Minutes on site against pages viewed, by device"
xLabel="Minutes on site"
yLabel="Pages"
series={[
{ name: 'Desktop', data: desktop },
{ name: 'Mobile', tone: 3, data: mobile },
]}
trend
/>
)
}Props
| Prop | Type | Default | What it does |
|---|---|---|---|
series | { name: string, data: { x: number, y: number, label?: string }[], tone?: 1-8, color?: string }[] | — | Series in legend order; colours default to --ds-chart-1, 2, 3… A point's label heads its tooltip. |
title / subtitle | ReactNode | — | Heading above the legend. |
xLabel / yLabel / formatX / formatY | string / (v) => string | — | Axis names (shown under the plot and in the tooltip) and tick formatting. |
height | number | 260 | Plot height in px; the width follows the container. |
pointSize / trend / grid | number / boolean / boolean | 4.5 / false / true | Point radius, a least-squares line per series, dashed horizontal grid lines. |
label / labels | string / { show(name), hide(name), point(series, point) } | — | Accessible name of the chart, legend button names and the sentence announced for a point. |
Accessibility
- The chart is an image with an accessible name; describe the takeaway in label.
- It is focusable: arrow keys step through points from left to right, Home and End jump, Escape clears, and each point is announced in a polite live region.
- Legend buttons are toggle buttons with aria-pressed and a “Show/Hide name” label; the hidden state also changes the swatch to an outline, so it is not colour alone.
- Reduced motion removes the pop-in, the trend draw and the tooltip glide.
Motion
Points: 460ms spring pop with a 22ms stagger. Trend: 900ms draw from 300ms. Focus: 220ms spring grow; tooltip glides 200ms.
Add it to your project
Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the component next to your own.
ScatterChart.jsxscatter-chart.csstokens.cssREADME.md
Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.

