Scatter chartFree
Points by two numbers, bubbles sized by area, groups, log axes, quadrants and trend lines; rows it can't place are counted.
npx shadcn@latest add https://beautifulcharts.dev/r/scatter-chart.jsonEngine: ยท
Code
"use client";
import { ScatterChart } from "@/components/beautiful-charts/themes/instrument/recharts/scatter-chart";
import type { ChartConfig } from "@/components/beautiful-charts/core/contracts";
const data = [
{ team: "Atlas", cycle: 3.1, bugs: 4, size: 12 }, { team: "Beacon", cycle: 2.2, bugs: 2, size: 7 },
{ team: "Cobalt", cycle: 5.4, bugs: 11, size: 20 }, { team: "Drift", cycle: 2.8, bugs: 3, size: 9 },
{ team: "Ember", cycle: 4.0, bugs: 7, size: 15 }, { team: "Fjord", cycle: null, bugs: 1, size: 5 }, // not drawn, and counted
];
// Entries for the fields set labels and formats; bubbles are sized by area, so twice the people looks twice as big.
const config = {
cycle: { label: "Cycle time", format: (days: number) => `${days} d` },
bugs: { label: "Bugs" },
size: { label: "People" },
} satisfies ChartConfig;
export function CycleTimeAndBugs() {
return <ScatterChart data={data} xKey="cycle" yKey="bugs" sizeKey="size" nameKey="team" config={config} trend labelPoints="top" title="Longer cycles, more bugs" />;
}
Props
xKey*
keyof TDatum & string
The field for the horizontal position (a number).
yKey*
keyof TDatum & string
The field for the vertical position (a number).
sizeKey
keyof TDatum & string
A field that sizes each point by area, making a bubble chart.
groupKey
keyof TDatum & string
A field that sorts points into coloured groups. Group names are the keys of
config.nameKey
keyof TDatum & string
A field naming each point, for tooltips, the table and labels.
labelPoints
string[] | "top"
Label these points on the chart (by name), or the largest few ("top").
xScale
"linear" | "log"
"linear" (default) or "log" (powers of ten).
yScale
"linear" | "log"
"linear" (default) or "log" (powers of ten).
trend
boolean
Draw a least-squares trend line per group (or for all points without groups).
quadrants
{ x: number; y: number; labels?: [string, string, string, string] }
Split the plot into quadrants at these values, with optional labels (top-left, top-right, bottom-left, bottom-right).
maxRadius
number
Largest bubble radius in px (default 22).
radius
number
Point radius when there's no
sizeKey, in px (default 4.5).grid
boolean
Draw grid lines behind the plot. On by default.
xAxis
AxisOptions
Horizontal axis: hide it, format ticks, or add a label (defaults to the x field's label).
yAxis
AxisOptions
Vertical axis: hide it, format ticks, or add a label (defaults to the y field's label).
| Prop | Type | Description |
|---|---|---|
| xKey* | keyof TDatum & string | The field for the horizontal position (a number). |
| yKey* | keyof TDatum & string | The field for the vertical position (a number). |
| sizeKey | keyof TDatum & string | A field that sizes each point by area, making a bubble chart. |
| groupKey | keyof TDatum & string | A field that sorts points into coloured groups. Group names are the keys of config. |
| nameKey | keyof TDatum & string | A field naming each point, for tooltips, the table and labels. |
| labelPoints | string[] | "top" | Label these points on the chart (by name), or the largest few ("top"). |
| xScale | "linear" | "log" | "linear" (default) or "log" (powers of ten). |
| yScale | "linear" | "log" | "linear" (default) or "log" (powers of ten). |
| trend | boolean | Draw a least-squares trend line per group (or for all points without groups). |
| quadrants | { x: number; y: number; labels?: [string, string, string, string] } | Split the plot into quadrants at these values, with optional labels (top-left, top-right, bottom-left, bottom-right). |
| maxRadius | number | Largest bubble radius in px (default 22). |
| radius | number | Point radius when there's no sizeKey, in px (default 4.5). |
| grid | boolean | Draw grid lines behind the plot. On by default. |
| xAxis | AxisOptions | Horizontal axis: hide it, format ticks, or add a label (defaults to the x field's label). |
| yAxis | AxisOptions | Vertical axis: hide it, format ticks, or add a label (defaults to the y field's label). |
Props every chart shares (34): data, config, header, states, legend, tooltip, formatting, motion and selection
data*
TDatum[]
Your rows, as they are. Missing values (null, undefined, NaN) stay missing and are never drawn as zero.
locale
string
BCP 47 locale. Defaults to "en-US" so server and client render the same text.
timeZone
string
IANA time zone for dates. Defaults to "UTC" so server and client agree.
config
ChartConfig
Per-series label, colour, icon, format and style, keyed by series key. shadcn ChartConfig works as it is.
eyebrow
ReactNode
Small label above the title.
title
ReactNode
Card title. A string also names the chart for screen readers.
description
ReactNode
A line under the title.
takeaway
ReactNode | ((summary: string) => ReactNode) | false
The sentence under the title. Computed from the data by default; pass text, a function of the computed sentence, or false to hide it.
ariaDescription
string
Accessible summary for screen readers. Computed from the data by default.
motion
MotionPreference
"full" (default), "subtle" or "off". Reduced-motion settings always win.
motionOptions
MotionOptions
When the entrance plays.
sound
boolean
Sound cues on hover, scrub and select. Plays only if the visitor has also turned sound on for the page.
density
Density
"comfortable" (default) or "compact" for dashboards.
legend
LegendOptions | false
Legend position, alignment, shape and click action, or false to hide it.
tooltip
TooltipOptions<TDatum> | false
Tooltip position, indicator, cursor and custom content, or false to turn it off.
valueFormatter
(value: number) => string
Values formatted for display. Series formatters in config win.
loading
boolean
Show the loading state. Over existing data, the old marks stay dimmed instead of vanishing.
error
string | null
An error message. Shows the error state in place of the plot.
emptyState
ReactNode
Shown instead of the plot when there is no data.
loadingState
ReactNode
Shown while
loadingis true and there is no data yet.errorState
ReactNode
Shown when
erroris set.selected
number | null
Controlled and uncontrolled interaction state. Point selection (
selected) pins one row by its index indata. Series selection (selectedSeries) picks one series and dims the others. They are separate: picking a row doesn't pick a series.defaultSelected
number | null
Initial selected row when uncontrolled.
selectedSeries
string | null
Controlled series selection: this series stays lit and the others dim.
defaultSelectedSeries
string | null
Initial series selection when uncontrolled.
hidden
string[]
Controlled hidden series keys.
defaultHidden
string[]
Series hidden at first when uncontrolled.
activeIndex
number | null
Controlled hover or focus index, for syncing several charts on one cursor.
palette
"theme" | "shadcn"
Series colours: "theme" (default) uses the theme's designed palette; "shadcn" uses your --chart-1..5. --bc-series-N always wins. You can also opt a whole section in with the class bc-use-shadcn-colors.
table
boolean
Show the "Show data table" disclosure. On by default.
stats
ChartStat[]
A row of figures under the title, for dashboard cards and blocks.
footer
ReactNode
A line or action at the bottom of the card, e.g. a source note or a link.
className
string
Classes on the card, for spacing and layout.
height
number
Height of the plot area in px. The frame sizes around it.
| Prop | Type | Description |
|---|---|---|
| data* | TDatum[] | Your rows, as they are. Missing values (null, undefined, NaN) stay missing and are never drawn as zero. |
| locale | string | BCP 47 locale. Defaults to "en-US" so server and client render the same text. |
| timeZone | string | IANA time zone for dates. Defaults to "UTC" so server and client agree. |
| config | ChartConfig | Per-series label, colour, icon, format and style, keyed by series key. shadcn ChartConfig works as it is. |
| eyebrow | ReactNode | Small label above the title. |
| title | ReactNode | Card title. A string also names the chart for screen readers. |
| description | ReactNode | A line under the title. |
| takeaway | ReactNode | ((summary: string) => ReactNode) | false | The sentence under the title. Computed from the data by default; pass text, a function of the computed sentence, or false to hide it. |
| ariaDescription | string | Accessible summary for screen readers. Computed from the data by default. |
| motion | MotionPreference | "full" (default), "subtle" or "off". Reduced-motion settings always win. |
| motionOptions | MotionOptions | When the entrance plays. |
| sound | boolean | Sound cues on hover, scrub and select. Plays only if the visitor has also turned sound on for the page. |
| density | Density | "comfortable" (default) or "compact" for dashboards. |
| legend | LegendOptions | false | Legend position, alignment, shape and click action, or false to hide it. |
| tooltip | TooltipOptions<TDatum> | false | Tooltip position, indicator, cursor and custom content, or false to turn it off. |
| valueFormatter | (value: number) => string | Values formatted for display. Series formatters in config win. |
| loading | boolean | Show the loading state. Over existing data, the old marks stay dimmed instead of vanishing. |
| error | string | null | An error message. Shows the error state in place of the plot. |
| emptyState | ReactNode | Shown instead of the plot when there is no data. |
| loadingState | ReactNode | Shown while loading is true and there is no data yet. |
| errorState | ReactNode | Shown when error is set. |
| selected | number | null | Controlled and uncontrolled interaction state. Point selection (selected) pins one row by its index in data. Series selection (selectedSeries) picks one series and dims the others. They are separate: picking a row doesn't pick a series. |
| defaultSelected | number | null | Initial selected row when uncontrolled. |
| selectedSeries | string | null | Controlled series selection: this series stays lit and the others dim. |
| defaultSelectedSeries | string | null | Initial series selection when uncontrolled. |
| defaultHidden | string[] | Series hidden at first when uncontrolled. |
| activeIndex | number | null | Controlled hover or focus index, for syncing several charts on one cursor. |
| palette | "theme" | "shadcn" | Series colours: "theme" (default) uses the theme's designed palette; "shadcn" uses your --chart-1..5. --bc-series-N always wins. You can also opt a whole section in with the class bc-use-shadcn-colors. |
| table | boolean | Show the "Show data table" disclosure. On by default. |
| stats | ChartStat[] | A row of figures under the title, for dashboard cards and blocks. |
| footer | ReactNode | A line or action at the bottom of the card, e.g. a source note or a link. |
| className | string | Classes on the card, for spacing and layout. |
| height | number | Height of the plot area in px. The frame sizes around it. |
Events (5)
onSelectedChange
(selection: Selection<TDatum> | null) => void
Called when a row is selected or cleared, by pointer, keyboard or the data table.
onSelectedSeriesChange
(key: string | null) => void
Called when the selected series changes (legend "select" action, or a click on a series).
onHiddenChange
(hidden: string[]) => void
Called when the legend hides or shows a series.
onActiveChange
(index: number | null) => void
Called as the hovered or focused row changes, or null when it leaves.
onReady
(chart: EChartsType) => void
Called once with the ECharts instance, e.g. to add event listeners.
| Prop | Type | Description |
|---|---|---|
| onSelectedChange | (selection: Selection<TDatum> | null) => void | Called when a row is selected or cleared, by pointer, keyboard or the data table. |
| onSelectedSeriesChange | (key: string | null) => void | Called when the selected series changes (legend "select" action, or a click on a series). |
| onHiddenChange | (hidden: string[]) => void | Called when the legend hides or shows a series. |
| onActiveChange | (index: number | null) => void | Called as the hovered or focused row changes, or null when it leaves. |
| onReady | (chart: EChartsType) => void | Called once with the ECharts instance, e.g. to add event listeners. |
Recharts build only (1)
children
ReactNode
Recharts children render inside the same ScatterChart, which receives your original rows.
| Prop | Type | Description |
|---|---|---|
| children | ReactNode | Recharts children render inside the same ScatterChart, which receives your original rows. |
Apache ECharts build only (2)
renderer
EChartsRenderer
"canvas" (default, best for many points) or "svg".
option
OptionOverride
Deep-merged over the generated option, or
(generated) => option. Points are custom series "points" (one item per point); trend lines are "trends".
| Prop | Type | Description |
|---|---|---|
| renderer | EChartsRenderer | "canvas" (default, best for many points) or "svg". |
| option | OptionOverride | Deep-merged over the generated option, or (generated) => option. Points are custom series "points" (one item per point); trend lines are "trends". |
Accessibility, keyboard and motion
- Pointer
- Hover a point to show its values; click pins it. The keyboard visits points in x order.
- Keyboard
- Tab lands once on the plot. Left and Right move between points (the first press goes to the latest), Up and Down change series, Home and End jump to the ends, Enter or Space pins, Escape clears.
- Screen readers
- Every move is announced as a sentence, not coordinates. "Show data table" opens the numbers as a real table, and missing values stay empty, never zero.
- Motion
- Points pop in by position, then the trend line draws. With reduced motion everything appears settled at once, and nothing depends on the motion to be read.