Scatter Chart
A scatter and bubble chart recipe - Recharts drawn with Appica UI tokens, for 2 or 3 measures per item.
A scatter chart plots each item by 2 measures to show how they relate, and a bubble chart adds a third as size. Like every chart here it is a recipe: Recharts draws it and the chart layer themes it. Each example below is a complete file to paste and adapt.
Installation
Recharts is the only extra dependency, with react-is at the same version as react:
pnpm add recharts react-isThe examples import the chart layer from @/components/chart. If your project doesn't have it yet, copy it from the Charts page first.
Examples
Default
Both axes are numeric and each Scatter holds its own data. A point can sit next to any other, so use the first 3 series colors only, and a stroke in the surface color keeps overlapping points apart. The tooltip takes its heading from the hovered row through a small wrapper around ChartTooltip, defined outside the chart so it keeps its state between renders.
Bubble
ZAxis maps a third measure to the area of each point. A bubble is the -soft tint with a 1 px outline, so overlapping bubbles stay readable, and with 1 series the tooltip hides its swatches.
Accessibility
- Pass
aria-labelto the chart with what it shows ("Products by price and rating, sized by sales"). It becomes the accessible name of the SVG. - The chart takes focus, and the arrow keys move the tooltip from point to point.
- Name both axes with
name, since the tooltip prints those names beside the values. - A chart with 2 or 3 groups has a
Legend. Past 3 groups, draw 1 chart per group. - Nothing animates under reduced motion.