Cómo funciona
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.
Úsalo para
- Showing whether two measures move together, and how groups differ: time against pages, price against rating, size against duration.
Busca otra opción cuando
- Thousands of points: draw them on a canvas or bin them into a heatmap.
- Values over time: use a line chart.
Uso
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
/>
)
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
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. |
Accesibilidad
- 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.
Movimiento
Points: 460ms spring pop with a 22ms stagger. Trend: 900ms draw from 300ms. Focus: 220ms spring grow; tooltip glides 200ms.
Añádelo a tu proyecto
Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.
ScatterChart.jsxscatter-chart.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

