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.
xLabelandyLabelsay what each axis measures;formatX,formatYandformatSizehow it is written.xMin,xMax,yMinandyMaxfix each scale.labelon a point names it in the tooltip and in the table.loadinganderrorsay 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
- Rings
- Necklaces
| Series | Point | Price | Units sold |
|---|---|---|---|
| Rings | Aurelia | 120 € | 340 |
| Rings | Vera | 180 € | 290 |
| Rings | Nora | 240 € | 210 |
| Rings | Lía | 310 € | 180 |
| Rings | Elda | 420 € | 95 |
| Necklaces | Alba | 90 € | 260 |
| Necklaces | Iris | 150 € | 240 |
| Necklaces | Sira | 220 € | 150 |
| Necklaces | Oda | 280 € | 130 |
| Necklaces | Tea | 390 € | 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.
| Prop | Type | What it does |
|---|---|---|
labelrequired | string | What is being measured. Required: a chart without a title does not inform. |
seriesrequired | readonly ScatterSeries[] | The series: `{ key, label, points, tone? }`, and each point `{ x, y, size?, label? }`. With `size`, it is a bubble. |
className | string | Merged with the library classes; it does not replace them. |
error | ReactNode | The 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 | — |
height | number | Height of the drawing in pixels. By default, that of the size. |
hiddenSeries | readonly string[] | The keys of the hidden series, when the chart's user keeps them. Without it, the chart keeps them itself. |
legend | boolean | The legend with the name of each series. By default, only if there is more than one. |
loading | boolean | The 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[]) => void | Called with the hidden keys after a legend entry is pressed. |
onPointPress | (point: ScatterPointPress) => void | Turns each point into a button and hands over the pressed one. |
size | "sm" | "md" | "lg" | — |
sizeLabel | string | What the size of the bubble is called. |
tableVisible | boolean | Also shows the table. For the screen reader it is always there. |
toggleSeries | boolean | The legend stops being a label and each entry becomes a button that hides or brings back its series. |
xLabel | string | What the bottom axis is called. |
xMax | number | — |
xMin | number | — |
yLabel | string | What the left axis is called. |
yMax | number | — |
yMin | number | — |
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:
