Skip to content
EspañolEnglish
All components (283)

Scatter chart

Data · ScatterChart

What it is and when to use it

Points on two numeric axes, to see whether two measures go together: price and sales, hours and cost. With size on the points they are bubbles and a third measure comes in.

The drawing is the decoration and the table is the data: underneath goes a real table, with one row per point, hidden from view unless tableVisible.

When to use it

  • Looking for a relationship between two measures, or the points that fall outside it.
  • Comparing groups with several series: each with its colour and the shape of its point.
  • xLabel and yLabel say what each axis measures; formatX, formatY and formatSize how it is written. xMin, xMax, yMin and yMax fix each scale.
  • label on a point names it in the tooltip and in the table.
  • loading and error say so in the place of the drawing, with the same height.

When not to

  • A measure that evolves over time: LineChart.
  • Bars and a line over the same period: ComboChart.
  • Thousands of points: here each point is a document node. Up to a few hundred is fine.

Keyboard: Tab takes you to the drawing (a single tab stop) and the arrows move from point to point, series by series and from left to right; Home and End go to the first and last, and Escape leaves. A spoken notice says each point. With onPointPress, each point is a button and Tab reaches it.

Accessibility: the drawing is an image (role="img") with a written summary of the range each series moves in. Series are also told apart by the shape of the point. The area of a bubble is proportional to its value, not the diameter: with the diameter, double the value would look four times bigger.

Fine look: --amset-scatter-point is the size of a point without size, and the --amset-series-* of the other charts apply: -axis, -cap, -footer, -height, -label.

What it looks like

Units soldPriceUse the arrow keys to move through the values, Home and End to jump to the first and last, and Escape to leave.
  • Rings
  • Necklaces
Price and units sold per model
SeriesPointPriceUnits sold
RingsAurelia120 €340
RingsVera180 €290
RingsNora240 €210
RingsLía310 €180
RingsElda420 €95
NecklacesAlba90 €260
NecklacesIris150 €240
NecklacesSira220 €150
NecklacesOda280 €130
NecklacesTea390 €70

<ScatterChart
  label="Price and units sold per model"
  series={[
    { key: "anillos", label: "Rings", points: [{ x: 120, y: 340, label: "Aurelia" }, { x: 420, y: 95, label: "Elda" }] },
  ]}
  xLabel="Price"
  yLabel="Units sold"
  formatX={enEuros}
/>

Props

Import it with import { ScatterChart } from '@amset/ui'. Required props are marked.

PropTypeWhat it does
labelrequiredstringWhat is being measured. Required: a chart without a title does not inform.
seriesrequiredreadonly ScatterSeries[]The series: `{ key, label, points, tone? }`, and each point `{ x, y, size?, label? }`. With `size`, it is a bubble.
classNamestringMerged with the library classes; it does not replace them.
errorReactNodeThe data has not arrived: it says so in the place of the drawing, with what is passed here.
formatSize(value: number) => string—
formatX(value: number) => string—
formatY(value: number) => string—
heightnumberHeight of the drawing in pixels. By default, that of the size.
hiddenSeriesreadonly string[]The keys of the hidden series, when the chart's user keeps them. Without it, the chart keeps them itself.
legendbooleanThe legend with the name of each series. By default, only if there is more than one.
loadingbooleanThe data is on its way: a notice appears in the place of the drawing, and the page does not jump when it arrives.
onHiddenSeriesChange(hidden: readonly string[]) => voidCalled with the hidden keys after a legend entry is pressed.
onPointPress(point: ScatterPointPress) => voidTurns each point into a button and hands over the pressed one.
size"sm" | "md" | "lg"—
sizeLabelstringWhat the size of the bubble is called.
tableVisiblebooleanAlso shows the table. For the screen reader it is always there.
toggleSeriesbooleanThe legend stops being a label and each entry becomes a button that hides or brings back its series.
xLabelstringWhat the bottom axis is called.
xMaxnumber—
xMinnumber—
yLabelstringWhat the left axis is called.
yMaxnumber—
yMinnumber—

It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.

In the test bench

Every state and variant, to try one at a time, on its page at storybook.amsetui.com: