Skip to content

Scatter Plot and Bubble Chart for React

A React scatter plot and bubble chart that shows how two measures relate, one dot per item, with an optional trend line. Pass series as readonly ScatterSeries[]: each a label plus a data array of { x, y } points, with an optional size for bubbles.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/scatter-chart.json

Ad spend vs revenue

  • Search
  • Social
Search trend: slope 2.98 per unit of x, R² 0.98. Social trend: slope 2.04 per unit of x, R² 0.95. Use the arrow keys to move between points: left and right follow x, up and down follow y.

Scatter with trend lines

Two series, each with its own fitted trend (dotted, so it never reads as data). Their slope and R² are part of the chart's accessible name.

Ad spend vs revenue

One dot per week

  • Search
  • Social

Files to copy

11 folders · 25 files · 4 packages
From theme/src/
  • components/charts/{scatter-chart.tsx, chart-export-menu.tsx, chart-export.ts, chart-figure.tsx, chart-fit.tsx, chart-icons.tsx, chart-parts.tsx, chart-patterns.tsx, chart-utils.ts}
  • components/charts/chart-parts/
  • components/drawer/parts/sheet.tsx
  • components/kbd/
  • components/menu/
  • components/skeleton/
  • components/status-icons/
  • hooks/{use-controllable.ts, use-intersection.ts, use-latest.ts, use-media-query.ts, use-preferences.ts}
  • motion/tokens.ts
  • lib/{cn.ts, csv.ts, form.ts, glide-highlight.tsx, heading.ts, math.ts, popup-a11y.ts, popup-motion.ts, warn-once.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/scatter-chart.jsonRegistry item: scatter-chart. The styles need the Tailwind v4 glass UI setup.
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Next.js: samples here pass functions (formatters, seriesLegend, a dashboard's load), so put them in a file that starts with "use client".

Bubble chart

bubble sizes each point by area (4× the population is 4× the ink, not 16×). Big bubbles sit behind small ones, each with a surface ring, so every city stays visible and reachable.

Rent vs salary

Monthly, in euros; bubble size is population

  • Europe
  • Asia
  • Americas

Edge cases

A single point gets a padded axis around it; a fourth series folds into a neutral “Other” (in a scatter every color is compared with every other, so three is the limit).

One point

Four series

  • Europe
  • Asia
  • Americas
  • Other

ScatterChart props

PropTypeDefaultDescription
series (required)readonly ScatterSeries[]NoneUp to 3 series: in a scatter every colour sits next to every other, so a 4th would be hard to tell apart. Series past the third fold into one neutral "Other" series.
xLabelstringNoneName of the x measure: titles the axis and the tooltip.
yLabelstringNoneName of the y measure: titles the axis and the tooltip.
sizeLabelstringNoneSets the name of the size measure (bubble charts).
bubblebooleanfalseSize each point by its size (a bubble chart).
trendlinebooleanfalseDraw a least-squares trend line through each series (needs 2+ points with different x).
includeZerobooleanfalseKeep 0 on the axes even when the data sits far from it.
heightnumber300Height of the chart in px; the width follows the container.
formatX((n: number) => string)formatCompactFormats x values on the axis and in the tooltip.
formatY((n: number) => string)formatCompactFormats y values on the axis and in the tooltip.
formatSize((n: number) => string)formatCompactFormats bubble sizes in the tooltip.
emptyStateReactNodeNoneShown when there is nothing to plot.
labelsPartial<ScatterChartLabels>defaultScatterChartLabelsEvery other string, for translation: labels={{ x: "…" }}; omitted keys keep the English of defaultScatterChartLabels. All 10 keys of ScatterChartLabels are listed in the key table under the props table.
aria-label (required)stringNoneNames the chart for assistive tech (required).
classNamestringNoneAdds extra classes to the outer element.
scatterLegend(series)LegendItem[]NoneReturns legend items with the same “Other” fold.
linearRegression(points){ slope, intercept, r2 } | nullNoneThe fit the trend line uses.
ScatterChartLabels keys and English defaults (10)
Pass any key in labels; the rest keep the defaults of defaultScatterChartLabels.
KeyEnglish default
xx
yy
sizeSize
otherOther
seriesSeries
pointPoint
noDataNo data
instructionsUse the arrow keys to move between points: left and right follow x, up and down follow y.
touchHintTap near a point to read it.
trendSummary(series, slope, r2) => `${series} trend: slope ${slope} per unit of x, R² ${r2}.`

ScatterTable props

PropTypeDefaultDescription
labelsPartial<ScatterChartLabels>defaultScatterChartLabelsEvery other string, for translation: labels={{ x: "…" }}; omitted keys keep the English of defaultScatterChartLabels. All 10 keys of ScatterChartLabels are listed in the key table under the props table.
series (required)readonly ScatterSeries[]NoneUp to 3 series: in a scatter every colour sits next to every other, so a 4th would be hard to tell apart. Series past the third fold into one neutral "Other" series.
bubblebooleanfalseSize each point by its size (a bubble chart).
xLabelstringNoneName of the x measure: titles the axis and the tooltip.
yLabelstringNoneName of the y measure: titles the axis and the tooltip.
sizeLabelstringNoneSets the name of the size measure (bubble charts).
formatX((n: number) => string)formatCompactFormats x values on the axis and in the tooltip.
formatY((n: number) => string)formatCompactFormats y values on the axis and in the tooltip.
formatSize((n: number) => string)formatCompactFormats bubble sizes in the tooltip.
captionstringNoneSets a visually hidden caption that names the table.

Keyboard

KeysAction
TabFocus the chart. It is one tab stop; the arrow keys then read it.
→/←Next / previous point in x order.
↑/↓Next / previous point in y order.
Home/EndJump to the first / last point in x order.
EscapeClear the reading.

Accessibility

  • The chart is one focusable figure: its aria-label is the chart title, a one-line hint describes how to read it, and in a ChartCard with a table view aria-details points at that table. Each move is announced politely, once. Each move announces the point's x, y (and size, for bubbles).
  • ScatterTable is the same data as a real table. Pass it to ChartCard's table prop and the Chart / Table tabs let anyone read every value without color or sight.
  • With reduced motion on, the points start at their final positions and a data change jumps straight to the new state.

All exports on this page

  • MAX_SCATTER_SERIES — In a scatter every colour is compared with every other ("all pairs"): three is the safe limit.
  • ScatterChart — A scatter plot of x against y, with optional bubble sizes and trendline.
  • ScatterTable — The table view of a scatter chart: one row per point, grouped by series (with the same "Other" fold).
  • defaultScatterChartLabels — The built-in English strings of ScatterChart; spread it into your own labels and change what you need.
  • foldScatterSeries — The series as drawn: the first three keep their colour slot, the rest fold into a neutral "Other".
  • linearRegression — Least-squares fit y = slope * x + intercept, with R².
  • scatterLegend — Legend items for a scatter chart, with the same "Other" fold as the chart.

When to use the scatter plot and bubble chart

  • Use it as a scatter chart with a trend line for ad spend against revenue per week, where you want to see whether two measures move together and quantify the relationship with a fitted line.
  • It suits a bubble chart of cities, plotting rent against salary with bubble area showing population so a small number of large points stays visible.
  • It works for comparing up to three groups, such as two campaigns, each with its own series color and its own trend line with slope and R squared.
  • Skip it when one axis is categorical or time, where LineChart or BarChart fit better; for thousands of points of one variable, Beeswarm or Histogram shows the distribution more clearly.
  • Pair it with ChartCard for the title, legend and Chart / Table tabs, ScatterTable for the text twin, and scatterLegend so a folded Other series is labeled the same way.

Frequently asked questions

48 charts pages in all: browse them on Charts.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .