Sankey chartFree
Flows with validation, disclosures and path tracing. Same props and layout on both engines.
npx shadcn@latest add https://beautifulcharts.dev/r/sankey-chart.jsonEngine: ·
Code
"use client";
import { SankeyChart } from "@/components/beautiful-charts/themes/instrument/recharts/sankey-chart";
const data = {
nodes: [
{ id: "visits", label: "Visits" }, { id: "signup", label: "Sign-ups" }, { id: "left", label: "Left" },
{ id: "trial", label: "Trials" }, { id: "paid", label: "Paid" }, { id: "churn", label: "Churned" },
],
links: [
{ source: "visits", target: "signup", value: 4200 }, { source: "visits", target: "left", value: 9800 },
{ source: "signup", target: "trial", value: 2600 }, { source: "trial", target: "paid", value: 880 },
{ source: "trial", target: "churn", value: 1720 },
],
};
// Selecting a node traces its path; `members` lists the links on it as indexes into `links`.
export function SignupFlow() {
return <SankeyChart data={data} title="From visit to paid" onSelectedChange={(selection) => console.log(selection?.datum.label, selection?.members)} />;
}
Props
data*
SankeyData
Nodes and links. Links to unknown nodes, cycles and negative values are reported, never drawn as if valid.
config
ChartConfig
Keyed by node id: label, colour, format.
nodeWidth
number
Node width in px.
nodePadding
number
Vertical gap between nodes in a column, in px.
align
"justify" | "left"
"justify" puts sinks in the last column; "left" keeps each node at its depth.
linkColor
"source" | "target" | "gradient" | "neutral"
Link colour: from the source node, the target node, a gradient between them, or neutral.
labels
"outside" | "none"
Node labels beside the node, with or without the value.
showValues
boolean
Add each node's total beside its label.
curvature
number
Pixel curvature of links, 0–1.
| Prop | Type | Description |
|---|---|---|
| data* | SankeyData | Nodes and links. Links to unknown nodes, cycles and negative values are reported, never drawn as if valid. |
| config | ChartConfig | Keyed by node id: label, colour, format. |
| nodeWidth | number | Node width in px. |
| nodePadding | number | Vertical gap between nodes in a column, in px. |
| align | "justify" | "left" | "justify" puts sinks in the last column; "left" keeps each node at its depth. |
| linkColor | "source" | "target" | "gradient" | "neutral" | Link colour: from the source node, the target node, a gradient between them, or neutral. |
| labels | "outside" | "none" | Node labels beside the node, with or without the value. |
| showValues | boolean | Add each node's total beside its label. |
| curvature | number | Pixel curvature of links, 0–1. |
Props every chart shares (27): data, config, header, states, legend, tooltip, formatting, motion and selection
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.
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.
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.
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 |
|---|---|---|
| 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. |
| 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. |
| 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. |
| 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 (3)
onSelectedChange
(selection: SankeySelection | null) => void
Called when a node is selected or cleared. The selection carries the node and every link on its traced path.
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: SankeySelection | null) => void | Called when a node is selected or cleared. The selection carries the node and every link on its traced path. |
| 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. |
Apache ECharts build only (2)
renderer
EChartsRenderer
"canvas" (default) or "svg".
option
OptionOverride
Deep-merged over the generated option, or
(generated) => option. Links are custom series "links" (one item per link), nodes "nodes" (id = node id).
| Prop | Type | Description |
|---|---|---|
| renderer | EChartsRenderer | "canvas" (default) or "svg". |
| option | OptionOverride | Deep-merged over the generated option, or (generated) => option. Links are custom series "links" (one item per link), nodes "nodes" (id = node id). |
Accessibility, keyboard and motion
- Pointer
- Hover a node or link to highlight its whole path and show the flow; click pins it.
- 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
- Bars grow from the baseline, staggered in data order, then the labels fade in. The headline number rolls in. With reduced motion everything appears settled at once, and nothing depends on the motion to be read.