Skip to content

Sankey Diagram for React

A React Sankey diagram draws flows between stages as ribbons whose thickness is the amount, laid out without a chart library. Pass links as readonly SankeyLink[]: { source, target, value } objects, and optionally nodes with an id, a label and a color slot.

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

Where visitors came from, and where they went

Use the arrow keys to read it: up and down move between the nodes of a column, right and left follow the flows out of and into a node.

  • SankeyChart
  • SankeyTable
  • layoutSankey
  • sankeyLinkPath
  • defaultSankeyChartLabels
  • +3 more

Customer journey, morphing week to week

Ribbons fade from the source's color into the target's. Switch the week: nodes slide and ribbons reshape instead of redrawing. Focus the chart and use the arrow keys: up and down within a column, right to follow a node's flows out, right again to the next node.

Customer journey

Visitors this week, by source and first page

14.9Kvisitors

Income statement, revenue to profit

Four columns from revenue streams to profit. Sinks line up in the last column (align justify, the default). Values use a currency format; labels move outside the diagram on wide cards and inside on narrow ones, and are only printed where they fit.

Income statement

Fiscal 2025

$2.1Moperating profit

Files to copy

13 folders · 29 files · 4 packages
From theme/src/
  • components/charts/{sankey-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-tip.tsx, chart-utils.ts, flow-utils.tsx, heatmap.tsx}
  • components/charts/chart-parts/
  • components/charts/heatmap/
  • components/charts/sankey-chart/
  • 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, use-resolved-scheme.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/sankey-chart.jsonRegistry item: sankey-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".

Hiring pipeline, aligned left, colored by source

align="left" puts every node at its distance from the start, so candidates who drop out early stop early. linkColor="source" paints each ribbon in its source stage. Nodes named only in links take their id as the label. On a phone the five columns scroll sideways inside the card.

Hiring pipeline

Engineering roles, first half

41hired

Props

PropTypeDefaultDescription
links (required)readonly SankeyLink[]NoneFlows between nodes. A node named only here is created with its id as the label.
nodesreadonly SankeyNode[]NoneNames, colours and order of the nodes. Optional.
heightnumber360Sets the height of the diagram in px.
nodeWidthnumber12Sets the width of a node bar in px (≤ 24).
nodePaddingnumber16Gap between the nodes of a column in px.
alignSankeyAlign"justify"Column of each node: "justify" (default: sinks go to the last column), "left" (by distance from a source), "right" (by distance to a sink) or "center".
linkColor"source" | "target" | "gradient""gradient"Ribbon colour: a gradient from the source's colour to the target's (default), or either one.
minColumnWidthnumber96Narrowest space between two columns in px; a narrower card scrolls the diagram sideways.
format((n: number) => string)formatCompact in localeFormats a flow value for the labels, tooltips and data table: takes the number, returns the text shown.
formatPercent((ratio: number) => string)percentages in localeFormats a share as text (0–1).
localestring"en"Locale of the default number formats.
onNodeClick((node: { id: string; label: string; inflow: number; outflow: number; }) => void)NoneCalled on click / Enter on a node.
onLinkClick((link: { source: string; target: string; value: number; }) => void)NoneCalled on click / Enter on a flow.
emptyStateReactNodeNoneShown when there is nothing to plot.
patternsbooleantrue when node colours > 3Tell nodes apart without colour (hatch fills, one per node colour; the first colour stays solid). Ribbons keep their source-to-target gradient.
labelsPartial<SankeyChartLabels>defaultSankeyChartLabelsEvery other string, for translation: labels={{ roleDescription: "…" }}; omitted keys keep the English of defaultSankeyChartLabels. All 10 keys of SankeyChartLabels 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.
SankeyChartLabels keys and English defaults (10)
Pass any key in labels; the rest keep the defaults of defaultSankeyChartLabels.
KeyEnglish default
roleDescriptionsankey diagram
instructionsUse the arrow keys to read it: up and down move between the nodes of a column, right and left follow the flows out of and into a node.
hintTap a node or a flow to trace it
inflowin
outflowout
ofTotalof all flow
ofSource(source) => `of ${source} outflow`
ofTarget(target) => `of ${target} inflow`
linkTitle(source, target) => `${source} → ${target}`
linkCount(count) => `${count} ${count === 1 ? "flow" : "flows"}`

SankeyTable

PropTypeDefaultDescription
links (required)readonly SankeyLink[]NoneThe same flows as the chart: { source, target, value }.
nodesreadonly SankeyNode[]NoneOptional node labels and colours, as in the chart.
format((n: number) => string)compact numbers in localeFormats a flow value for the table cells: takes the number, returns the text shown.
formatPercent((ratio: number) => string)percentages in localeFormats a share of the total for the table cells: takes the share, returns the text shown.
localestring"en"Locale of the default number formats.
captionstringNoneHidden caption that names the table for screen readers.
headersPartial<{ source: string; target: string; value: string; ofSource: string; ofTarget: string; }>NoneOverride the column headers: { source, target, value, ofSource, ofTarget }.
emptyStateReactNodeNoneShown when there are no flows.

Keyboard

KeysAction
TabFocus the diagram (one stop; a narrow card scrolls it sideways to keep the active node in view).
↑/↓Previous / next node in the column; on a flow, the previous / next flow of the same node.
→/←Follow the node's first outgoing / incoming flow; on a flow, go on to its target / source node.
Home/EndFirst node of the first column / last node of the last column.
Enter/SpaceCall onNodeClick or onLinkClick for the active node or flow.
EscapeClear the reading.

Accessibility

  • The diagram is one focusable figure with the role description “sankey diagram”; its description is the keyboard instructions.
  • Keyboard moves are announced once through a polite live region (“Paid ads → Pricing page: 2.6K, 81% of Paid ads outflow, 28% of Pricing page inflow”); pointer hovers stay silent.
  • The Table view (SankeyTable) lists every flow with its share of both ends: the color-free way to read it.
  • On touch screens the first tap pins the readout in a band above the diagram; a second tap on the same mark activates it.
  • Reduced motion: the diagram appears complete and data changes jump. Forced colors: ribbons and nodes take system colors and the active node gets a Highlight ring.

All exports on this page

  • SankeyChart — Flows between stages as ribbons whose thickness is the amount: where traffic comes from and where it goes, a budget split, energy in and out.
  • SankeyTable — Every flow of a sankey as a table: from, to, amount, and its share of each end.
  • defaultSankeyChartLabels — The built-in English strings of SankeyChart; spread it into your own labels and change what you need.
  • layoutSankey — Lays out a sankey diagram in a width × height box: nodes in columns by their longest path from a source, sized by their flow.
  • sankeyLinkPath — The ribbon of a link: a horizontal S-curve from the source's right edge to the target's left edge.

When to use the sankey diagram

  • Use it as a Sankey chart for an income statement, tracing revenue streams through costs to profit, with ribbon thickness showing how much of each stream ends up where.
  • It fits a hiring pipeline or a signup funnel with drop-offs, where align left makes candidates who leave early stop early and linkColor source colors each ribbon by its source stage.
  • It also works as a user flow chart for traffic, showing where visitors come from and which pages they go to, with hover tracing every path through a node.
  • Skip it when flows are bidirectional or form cycles, since links that would close a cycle are left out; a ChordDiagram or NetworkGraph represents those, and FunnelChart suits a single linear sequence.
  • Pair it with ChartCard for the title and Chart / Table tabs, SankeyTable as the text version, and onNodeClick or onLinkClick to filter a DataTable beside it.

Frequently asked questions

48 charts pages in all: browse them on Charts.

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