Shadcn Scatter Chart
Free shadcn/ui scatter and bubble chart for React — built on Recharts and themed with CSS variables. Basic scatter, bubble (ZAxis sizing), multiple series, labeled axes, and custom shapes, plus loading, empty, and accessible states.
Installation
{
"registries": {
"@designrevision": "https://registry.designrevision.com/r/{name}.json"
}
}
Add to your existing components.json. Requires shadcn/ui v2.3+.
Packages
Props
config*
= —
ChartConfig
Maps each data key to { label, icon?, color }. Colors become --color-<key> CSS vars.
children*
= —
React.ReactElement (a Recharts chart)
A single Recharts chart (BarChart, LineChart, …) — ChartContainer wraps it in a ResponsiveContainer.
A Recharts wrapper themed with CSS variables. Pass a `config` (ChartConfig: each data key → { label, icon?, color }) to <ChartContainer>; it injects --color-<key> vars (scoped per light/dark theme) that your Recharts series reference as fill="var(--color-desktop)". Use <ChartTooltip content={<ChartTooltipContent />}> and <ChartLegend content={<ChartLegendContent />}> for themed tooltips/legends. Colors default to the --chart-1..5 tokens, which re-theme automatically in dark mode. The container needs a height — keep aspect-video / min-h-* or ResponsiveContainer measures 0. This is the base primitive; the Bar/Line/Area/Pie/Radar/Radial chart pages compose it.
"use client"
import * as React from "react"
import * as RechartsPrimitive from "recharts"
import { cn } from "@/lib/utils"
// Format: { THEME_NAME: CSS_SELECTOR }
const THEMES = { light: "", dark: ".dark" } as const
export type ChartConfig = {
[k in string]: {
label?: React.ReactNode
icon?: React.ComponentType
} & (
| { color?: string; theme?: never }
| { color?: never; theme: Record<keyof typeof THEMES, string> }
)
}
type ChartContextProps = {
config: ChartConfig
}
const ChartContext = React.createContext<ChartContextProps | null>(null)
function useChart() {
const context = React.useContext(ChartContext)
if (!context) {
throw new Error("useChart must be used within a <ChartContainer />")
}
return context
}
function ChartContainer({
id,
className,
children,
config,
...props
}: React.ComponentProps<"div"> & {
config: ChartConfig
children: React.ComponentProps<
typeof RechartsPrimitive.ResponsiveContainer
>["children"]
}) {
const uniqueId = React.useId()
const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`
return (
<ChartContext.Provider value={{ config }}>
<div
data-slot="chart"
data-chart={chartId}
className={cn(
"[&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border flex aspect-video justify-center text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",
className
)}
{...props}
>
<ChartStyle id={chartId} config={config} />
<RechartsPrimitive.ResponsiveContainer>
{children}
</RechartsPrimitive.ResponsiveContainer>
</div>
</ChartContext.Provider>
)
}
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
const colorConfig = Object.entries(config).filter(
([, config]) => config.theme || config.color
)
if (!colorConfig.length) {
return null
}
return (
<style
dangerouslySetInnerHTML={{
__html: Object.entries(THEMES)
.map(
([theme, prefix]) => `
${prefix} [data-chart=${id}] {
${colorConfig
.map(([key, itemConfig]) => {
const color =
itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ||
itemConfig.color
return color ? ` --color-${key}: ${color};` : null
})
.join("\n")}
}
`
)
.join("\n"),
}}
/>
)
}
const ChartTooltip = RechartsPrimitive.Tooltip
function ChartTooltipContent({
active,
payload,
className,
indicator = "dot",
hideLabel = false,
hideIndicator = false,
label,
labelFormatter,
labelClassName,
formatter,
color,
nameKey,
labelKey,
}: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
React.ComponentProps<"div"> & {
hideLabel?: boolean
hideIndicator?: boolean
indicator?: "line" | "dot" | "dashed"
nameKey?: string
labelKey?: string
}) {
const { config } = useChart()
const tooltipLabel = React.useMemo(() => {
if (hideLabel || !payload?.length) {
return null
}
const [item] = payload
const key = `${labelKey || item?.dataKey || item?.name || "value"}`
const itemConfig = getPayloadConfigFromPayload(config, item, key)
const value =
!labelKey && typeof label === "string"
? config[label as keyof typeof config]?.label || label
: itemConfig?.label
if (labelFormatter) {
return (
<div className={cn("font-medium", labelClassName)}>
{labelFormatter(value, payload)}
</div>
)
}
if (!value) {
return null
}
return <div className={cn("font-medium", labelClassName)}>{value}</div>
}, [
label,
labelFormatter,
payload,
hideLabel,
labelClassName,
config,
labelKey,
])
if (!active || !payload?.length) {
return null
}
const nestLabel = payload.length === 1 && indicator !== "dot"
return (
<div
className={cn(
"border-border/50 bg-background grid min-w-[8rem] items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl",
className
)}
>
{!nestLabel ? tooltipLabel : null}
<div className="grid gap-1.5">
{payload
.filter((item) => item.type !== "none")
.map((item, index) => {
const key = `${nameKey || item.name || item.dataKey || "value"}`
const itemConfig = getPayloadConfigFromPayload(config, item, key)
const indicatorColor = color || item.payload.fill || item.color
return (
<div
key={item.dataKey}
className={cn(
"[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5",
indicator === "dot" && "items-center"
)}
>
{formatter && item?.value !== undefined && item.name ? (
formatter(item.value, item.name, item, index, item.payload)
) : (
<>
{itemConfig?.icon ? (
<itemConfig.icon />
) : (
!hideIndicator && (
<div
className={cn(
"shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)",
{
"h-2.5 w-2.5": indicator === "dot",
"w-1": indicator === "line",
"w-0 border-[1.5px] border-dashed bg-transparent":
indicator === "dashed",
"my-0.5": nestLabel && indicator === "dashed",
}
)}
style={
{
"--color-bg": indicatorColor,
"--color-border": indicatorColor,
} as React.CSSProperties
}
/>
)
)}
<div
className={cn(
"flex flex-1 justify-between leading-none",
nestLabel ? "items-end" : "items-center"
)}
>
<div className="grid gap-1.5">
{nestLabel ? tooltipLabel : null}
<span className="text-muted-foreground">
{itemConfig?.label || item.name}
</span>
</div>
{item.value && (
<span className="text-foreground font-mono font-medium tabular-nums">
{item.value.toLocaleString()}
</span>
)}
</div>
</>
)}
</div>
)
})}
</div>
</div>
)
}
const ChartLegend = RechartsPrimitive.Legend
function ChartLegendContent({
className,
hideIcon = false,
payload,
verticalAlign = "bottom",
nameKey,
}: React.ComponentProps<"div"> &
Pick<RechartsPrimitive.LegendProps, "payload" | "verticalAlign"> & {
hideIcon?: boolean
nameKey?: string
}) {
const { config } = useChart()
if (!payload?.length) {
return null
}
return (
<div
className={cn(
"flex items-center justify-center gap-4",
verticalAlign === "top" ? "pb-3" : "pt-3",
className
)}
>
{payload
.filter((item) => item.type !== "none")
.map((item) => {
const key = `${nameKey || item.dataKey || "value"}`
const itemConfig = getPayloadConfigFromPayload(config, item, key)
return (
<div
key={item.value}
className={cn(
"[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3"
)}
>
{itemConfig?.icon && !hideIcon ? (
<itemConfig.icon />
) : (
<div
className="h-2 w-2 shrink-0 rounded-[2px]"
style={{
backgroundColor: item.color,
}}
/>
)}
{itemConfig?.label}
</div>
)
})}
</div>
)
}
// Helper to extract item config from a payload.
function getPayloadConfigFromPayload(
config: ChartConfig,
payload: unknown,
key: string
) {
if (typeof payload !== "object" || payload === null) {
return undefined
}
const payloadPayload =
"payload" in payload &&
typeof payload.payload === "object" &&
payload.payload !== null
? payload.payload
: undefined
let configLabelKey: string = key
if (
key in payload &&
typeof payload[key as keyof typeof payload] === "string"
) {
configLabelKey = payload[key as keyof typeof payload] as string
} else if (
payloadPayload &&
key in payloadPayload &&
typeof payloadPayload[key as keyof typeof payloadPayload] === "string"
) {
configLabelKey = payloadPayload[
key as keyof typeof payloadPayload
] as string
}
return configLabelKey in config
? config[configLabelKey]
: config[key as keyof typeof config]
}
export {
ChartContainer,
ChartTooltip,
ChartTooltipContent,
ChartLegend,
ChartLegendContent,
ChartStyle,
}
Examples
Scatter Chart
The canonical scatter chart — x/y points over a grid.
Packages
Props
No props documented yet.
"use client"
import { CartesianGrid, Scatter, ScatterChart, XAxis, YAxis } from "recharts"
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import {
type ChartConfig,
ChartContainer,
ChartTooltip,
ChartTooltipContent,
} from "@/components/ui/chart"
const chartData = [
{ x: 12, y: 230 },
{ x: 18, y: 290 },
{ x: 22, y: 250 },
{ x: 27, y: 340 },
{ x: 31, y: 300 },
{ x: 35, y: 410 },
{ x: 40, y: 360 },
{ x: 44, y: 470 },
{ x: 49, y: 430 },
{ x: 53, y: 520 },
{ x: 58, y: 480 },
{ x: 62, y: 560 },
]
const chartConfig = {
y: { label: "Revenue", color: "var(--chart-1)" },
} satisfies ChartConfig
export default function ScatterChartDemo01() {
return (
<Card className="w-full max-w-md">
<CardHeader>
<CardTitle>Scatter Chart</CardTitle>
<CardDescription>Visits vs. revenue</CardDescription>
</CardHeader>
<CardContent>
<ChartContainer config={chartConfig}>
<ScatterChart
accessibilityLayer
margin={{ top: 12, right: 12, bottom: 12, left: 12 }}
>
<CartesianGrid />
<XAxis
dataKey="x"
type="number"
name="Visits"
tickLine={false}
axisLine={false}
tickMargin={8}
/>
<YAxis
dataKey="y"
type="number"
name="Revenue"
tickLine={false}
axisLine={false}
tickMargin={8}
/>
<ChartTooltip
cursor={{ strokeDasharray: "3 3" }}
content={<ChartTooltipContent hideLabel />}
/>
<Scatter data={chartData} fill="var(--color-y)" />
</ScatterChart>
</ChartContainer>
</CardContent>
</Card>
)
}
Bubble chart
A third dimension via ZAxis — each point's size encodes a value.
Packages
Props
No props documented yet.
"use client"
import {
CartesianGrid,
Scatter,
ScatterChart,
XAxis,
YAxis,
ZAxis,
} from "recharts"
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import {
type ChartConfig,
ChartContainer,
ChartTooltip,
ChartTooltipContent,
} from "@/components/ui/chart"
const chartData = [
{ x: 12, y: 230, z: 120 },
{ x: 20, y: 290, z: 260 },
{ x: 26, y: 250, z: 80 },
{ x: 33, y: 360, z: 320 },
{ x: 38, y: 300, z: 160 },
{ x: 45, y: 430, z: 240 },
{ x: 51, y: 360, z: 90 },
{ x: 57, y: 500, z: 380 },
{ x: 63, y: 420, z: 140 },
{ x: 70, y: 560, z: 300 },
]
const chartConfig = {
y: { label: "Revenue", color: "var(--chart-1)" },
} satisfies ChartConfig
export default function ScatterChartBubble01() {
return (
<Card className="w-full max-w-md">
<CardHeader>
<CardTitle>Bubble Chart</CardTitle>
<CardDescription>Visits, revenue, and order size</CardDescription>
</CardHeader>
<CardContent>
<ChartContainer config={chartConfig}>
<ScatterChart
accessibilityLayer
margin={{ top: 12, right: 12, bottom: 12, left: 12 }}
>
<CartesianGrid />
<XAxis
dataKey="x"
type="number"
name="Visits"
tickLine={false}
axisLine={false}
tickMargin={8}
/>
<YAxis
dataKey="y"
type="number"
name="Revenue"
tickLine={false}
axisLine={false}
tickMargin={8}
/>
<ZAxis dataKey="z" type="number" range={[80, 500]} name="Order size" />
<ChartTooltip
cursor={{ strokeDasharray: "3 3" }}
content={<ChartTooltipContent hideLabel />}
/>
<Scatter
data={chartData}
fill="var(--color-y)"
fillOpacity={0.6}
/>
</ScatterChart>
</ChartContainer>
</CardContent>
</Card>
)
}
Multiple series
Two named series in distinct colors with a legend.
Packages
Props
No props documented yet.
"use client"
import { CartesianGrid, Scatter, ScatterChart, XAxis, YAxis } from "recharts"
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import {
type ChartConfig,
ChartContainer,
ChartLegend,
ChartLegendContent,
ChartTooltip,
ChartTooltipContent,
} from "@/components/ui/chart"
const groupA = [
{ x: 12, y: 200 },
{ x: 20, y: 260 },
{ x: 28, y: 230 },
{ x: 36, y: 300 },
{ x: 44, y: 280 },
{ x: 52, y: 340 },
]
const groupB = [
{ x: 16, y: 380 },
{ x: 24, y: 420 },
{ x: 32, y: 400 },
{ x: 40, y: 470 },
{ x: 48, y: 440 },
{ x: 56, y: 520 },
]
const chartConfig = {
groupA: { label: "Group A", color: "var(--chart-1)" },
groupB: { label: "Group B", color: "var(--chart-2)" },
} satisfies ChartConfig
export default function ScatterChartMultiple01() {
return (
<Card className="w-full max-w-md">
<CardHeader>
<CardTitle>Scatter Chart — Multiple</CardTitle>
<CardDescription>Two cohorts compared</CardDescription>
</CardHeader>
<CardContent>
<ChartContainer config={chartConfig}>
<ScatterChart
accessibilityLayer
margin={{ top: 12, right: 12, bottom: 12, left: 12 }}
>
<CartesianGrid />
<XAxis
dataKey="x"
type="number"
name="Visits"
tickLine={false}
axisLine={false}
tickMargin={8}
/>
<YAxis
dataKey="y"
type="number"
name="Revenue"
tickLine={false}
axisLine={false}
tickMargin={8}
/>
<ChartTooltip
cursor={{ strokeDasharray: "3 3" }}
content={<ChartTooltipContent hideLabel />}
/>
<ChartLegend content={<ChartLegendContent />} />
<Scatter name="groupA" data={groupA} fill="var(--color-groupA)" />
<Scatter name="groupB" data={groupB} fill="var(--color-groupB)" />
</ScatterChart>
</ChartContainer>
</CardContent>
</Card>
)
}
Labeled axes
Named, unit-bearing X and Y axes with a fixed domain.
Packages
Props
No props documented yet.
"use client"
import { CartesianGrid, Scatter, ScatterChart, XAxis, YAxis } from "recharts"
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import {
type ChartConfig,
ChartContainer,
ChartTooltip,
ChartTooltipContent,
} from "@/components/ui/chart"
const chartData = [
{ height: 160, weight: 54 },
{ height: 165, weight: 59 },
{ height: 168, weight: 63 },
{ height: 170, weight: 61 },
{ height: 173, weight: 68 },
{ height: 176, weight: 72 },
{ height: 178, weight: 70 },
{ height: 181, weight: 78 },
{ height: 184, weight: 81 },
{ height: 188, weight: 86 },
{ height: 191, weight: 90 },
{ height: 194, weight: 95 },
]
const chartConfig = {
weight: { label: "Weight", color: "var(--chart-3)" },
} satisfies ChartConfig
export default function ScatterChartAxes01() {
return (
<Card className="w-full max-w-md">
<CardHeader>
<CardTitle>Scatter Chart — Labeled Axes</CardTitle>
<CardDescription>Height vs. weight</CardDescription>
</CardHeader>
<CardContent>
<ChartContainer config={chartConfig}>
<ScatterChart
accessibilityLayer
margin={{ top: 12, right: 16, bottom: 12, left: 12 }}
>
<CartesianGrid />
<XAxis
dataKey="height"
type="number"
name="Height"
unit="cm"
domain={[155, 200]}
tickLine={false}
axisLine={false}
tickMargin={8}
/>
<YAxis
dataKey="weight"
type="number"
name="Weight"
unit="kg"
tickLine={false}
axisLine={false}
tickMargin={8}
/>
<ChartTooltip
cursor={{ strokeDasharray: "3 3" }}
content={<ChartTooltipContent hideLabel />}
/>
<Scatter data={chartData} fill="var(--color-weight)" />
</ScatterChart>
</ChartContainer>
</CardContent>
</Card>
)
}
Custom shapes
Three series, each with a distinct marker shape.
Packages
Props
No props documented yet.
"use client"
import { CartesianGrid, Scatter, ScatterChart, XAxis, YAxis } from "recharts"
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import {
type ChartConfig,
ChartContainer,
ChartLegend,
ChartLegendContent,
ChartTooltip,
ChartTooltipContent,
} from "@/components/ui/chart"
const desktop = [
{ x: 14, y: 220 },
{ x: 24, y: 280 },
{ x: 34, y: 250 },
{ x: 44, y: 330 },
{ x: 54, y: 360 },
]
const mobile = [
{ x: 18, y: 380 },
{ x: 28, y: 420 },
{ x: 38, y: 400 },
{ x: 48, y: 470 },
{ x: 58, y: 500 },
]
const tablet = [
{ x: 16, y: 120 },
{ x: 26, y: 160 },
{ x: 36, y: 140 },
{ x: 46, y: 190 },
{ x: 56, y: 210 },
]
const chartConfig = {
desktop: { label: "Desktop", color: "var(--chart-1)" },
mobile: { label: "Mobile", color: "var(--chart-2)" },
tablet: { label: "Tablet", color: "var(--chart-3)" },
} satisfies ChartConfig
export default function ScatterChartShapes01() {
return (
<Card className="w-full max-w-md">
<CardHeader>
<CardTitle>Scatter Chart — Shapes</CardTitle>
<CardDescription>A distinct marker per series</CardDescription>
</CardHeader>
<CardContent>
<ChartContainer config={chartConfig}>
<ScatterChart
accessibilityLayer
margin={{ top: 12, right: 12, bottom: 12, left: 12 }}
>
<CartesianGrid />
<XAxis
dataKey="x"
type="number"
name="Visits"
tickLine={false}
axisLine={false}
tickMargin={8}
/>
<YAxis
dataKey="y"
type="number"
name="Revenue"
tickLine={false}
axisLine={false}
tickMargin={8}
/>
<ChartTooltip
cursor={{ strokeDasharray: "3 3" }}
content={<ChartTooltipContent hideLabel />}
/>
<ChartLegend content={<ChartLegendContent />} />
<Scatter
name="desktop"
data={desktop}
fill="var(--color-desktop)"
shape="circle"
/>
<Scatter
name="mobile"
data={mobile}
fill="var(--color-mobile)"
shape="triangle"
/>
<Scatter
name="tablet"
data={tablet}
fill="var(--color-tablet)"
shape="cross"
/>
</ScatterChart>
</ChartContainer>
</CardContent>
</Card>
)
}
Loading state
A skeleton shaped like a scatter chart.
Packages
Props
No props documented yet.
import { Card, CardContent, CardHeader } from "@/components/ui/card"
import { Skeleton } from "@/components/ui/skeleton"
// A loading state for a scatter chart — scattered dot placeholders.
const dots = [
{ top: "18%", left: "12%" },
{ top: "55%", left: "22%" },
{ top: "32%", left: "35%" },
{ top: "70%", left: "44%" },
{ top: "40%", left: "56%" },
{ top: "22%", left: "66%" },
{ top: "60%", left: "74%" },
{ top: "38%", left: "86%" },
]
export default function ScatterChartLoading01() {
return (
<Card className="w-full max-w-md">
<CardHeader className="gap-2">
<Skeleton className="h-5 w-28" />
<Skeleton className="h-4 w-36" />
</CardHeader>
<CardContent>
<div className="relative aspect-video w-full">
{dots.map((dot, i) => (
<Skeleton
key={i}
className="absolute size-3 rounded-full"
style={dot}
/>
))}
</div>
</CardContent>
</Card>
)
}
Empty state
A graceful no-data state with a scatter icon.
Packages
Props
No props documented yet.
import { ChartScatter } from "lucide-react"
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
export default function ScatterChartEmpty01() {
return (
<Card className="w-full max-w-md">
<CardHeader>
<CardTitle>Scatter Chart</CardTitle>
<CardDescription>Visits vs. revenue</CardDescription>
</CardHeader>
<CardContent>
<div className="flex aspect-video flex-col items-center justify-center gap-2 rounded-lg border border-dashed text-center">
<ChartScatter className="text-muted-foreground size-8" />
<div className="text-sm font-medium">No data points</div>
<p className="text-muted-foreground max-w-[15rem] text-xs">
There's nothing to plot for this range yet.
</p>
</div>
</CardContent>
</Card>
)
}
Accessible
role/aria-label with a screen-reader data table of x/y pairs.
Packages
Props
No props documented yet.
"use client"
import { CartesianGrid, Scatter, ScatterChart, XAxis, YAxis } from "recharts"
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import {
type ChartConfig,
ChartContainer,
ChartTooltip,
ChartTooltipContent,
} from "@/components/ui/chart"
const chartData = [
{ x: 12, y: 230 },
{ x: 22, y: 290 },
{ x: 32, y: 340 },
{ x: 42, y: 410 },
{ x: 52, y: 470 },
{ x: 62, y: 560 },
]
const chartConfig = {
y: { label: "Revenue", color: "var(--chart-1)" },
} satisfies ChartConfig
export default function ScatterChartA11y01() {
return (
<Card className="w-full max-w-md">
<CardHeader>
<CardTitle>Accessible Scatter Chart</CardTitle>
<CardDescription>Visits vs. revenue, with a data table</CardDescription>
</CardHeader>
<CardContent>
<ChartContainer
config={chartConfig}
role="img"
aria-label="Scatter chart of revenue against visits across six points, trending upward from (12, 230) to (62, 560)."
>
<ScatterChart
accessibilityLayer
margin={{ top: 12, right: 12, bottom: 12, left: 12 }}
>
<CartesianGrid />
<XAxis
dataKey="x"
type="number"
name="Visits"
tickLine={false}
axisLine={false}
tickMargin={8}
/>
<YAxis
dataKey="y"
type="number"
name="Revenue"
tickLine={false}
axisLine={false}
tickMargin={8}
/>
<ChartTooltip
cursor={{ strokeDasharray: "3 3" }}
content={<ChartTooltipContent hideLabel />}
/>
<Scatter data={chartData} fill="var(--color-y)" />
</ScatterChart>
</ChartContainer>
{/* Visually-hidden data-table fallback for assistive technology. */}
<table className="sr-only">
<caption>Revenue by number of visits</caption>
<thead>
<tr>
<th scope="col">Visits</th>
<th scope="col">Revenue</th>
</tr>
</thead>
<tbody>
{chartData.map((row) => (
<tr key={row.x}>
<th scope="row">{row.x}</th>
<td>{row.y}</td>
</tr>
))}
</tbody>
</table>
</CardContent>
</Card>
)
}
The Shadcn Scatter Chart is a Recharts ScatterChart wrapped in the shadcn ChartContainer — themed with your --chart CSS variables and dark-mode-ready. It plots two numeric variables against each other to reveal correlation, clusters, and outliers, and with a ZAxis becomes a bubble chart. Below: basic, bubble, multiple series, labeled axes, and custom shapes, plus the production states.
The basic scatter chart
Both axes are numeric — that's what makes it a scatter rather than a bar/line:
const chartConfig = {
y: { label: "Revenue", color: "var(--chart-1)" },
} satisfies ChartConfig
<ChartContainer config={chartConfig}>
<ScatterChart margin={{ top: 12, right: 12, bottom: 12, left: 12 }}>
<CartesianGrid />
<XAxis dataKey="x" type="number" name="Visits" />
<YAxis dataKey="y" type="number" name="Revenue" />
<ChartTooltip cursor={{ strokeDasharray: "3 3" }} content={<ChartTooltipContent hideLabel />} />
<Scatter data={chartData} fill="var(--color-y)" />
</ScatterChart>
</ChartContainer>
Bubble chart
Add a third field and a ZAxis to size each point by a value:
<ZAxis dataKey="z" type="number" range={[80, 500]} name="Order size" />
<Scatter data={chartData} fill="var(--color-y)" fillOpacity={0.6} />
range sets the smallest and largest bubble area. Lower the fillOpacity so overlaps read.
Multiple groups & shapes
Render one <Scatter> per group with a name and a color, and add a legend. Give each a distinct shape — circle, triangle, cross, diamond, star, square, wye — when color alone isn't enough:
<Scatter name="desktop" data={desktop} fill="var(--color-desktop)" shape="circle" />
<Scatter name="mobile" data={mobile} fill="var(--color-mobile)" shape="triangle" />
<ChartLegend content={<ChartLegendContent />} />
Labeled axes
Name the axes, add units, and fix the domain for a real-data plot:
<XAxis dataKey="height" type="number" name="Height" unit="cm" domain={[155, 200]} />
<YAxis dataKey="weight" type="number" name="Weight" unit="kg" />
Production states
Loading (scattered-dot skeleton), empty (icon + message), and accessible (role/aria-label + a data table of x/y pairs) variants are included.
See Shadcn Charts for the theming system, dark mode, and the other chart types.