Skip to main content

Sankey chart

Where an amount goes: income into spending and savings, a budget into teams, visitors from their sources onto pages. Each source stacks on one side and each target on the other, joined by bands as wide as the flow they carry. Hover, press or drag over a bar or band to light it and dim the rest; on the web the chart takes keyboard focus and the arrow keys step through every bar and flow.

Import
import { SankeyChart } from '@patine-ui/pro';
Install
npx shadcn@latest add @patine-pro/sankey-chart
Source
Included with Patine ProMarkdown for LLMs
Runs on
iOSAndroidWebPRO
Loading…
<View style={{ width: '100%', maxWidth: 640, gap: 8 }}>
  <Text weight="semibold">Cash flow this month</Text>
  <SankeyChart
    data={proportionalFlows(income, spent)}
    sourceKey="source"
    targetKey="target"
    valueKey="value"
    valueFormat="currency"
    shareLabel={(p) => `${p} of money in`}
    accessibilityLabel="Cash flow this month"
  />
</View>

Try the props​

Props
linkColor
nodeWidth
valueFormat
design
<SankeyChart
data={flows}
sourceKey="from"
targetKey="to"
valueKey="amount"
/>

Examples​

A month's cash flow, income into spending and what was kept​

Money in is pooled before it's spent, so no payment belongs to one income. proportionalFlows pours every source into every target in proportion, which is how budgeting apps draw it. Add a "Kept" target for what's left, or a "From savings" source when spending ran over.

Loading…
<SankeyChart
  data={flows}
  sourceKey="source"
  targetKey="target"
  valueKey="value"
  valueFormat="currency"
  shareLabel={(p) => `${p} of December`}
  style={{ width: '100%', maxWidth: 640 }}
  accessibilityLabel="December, where the money went"
/>

A marketing budget split into channels​

When you know each flow, pass a row per flow. Name the nodes and pick their colours with series.

Loading…
<SankeyChart
  data={flows}
  sourceKey="from"
  targetKey="to"
  valueKey="amount"
  valueFormat="compact"
  series={[{ key: 'Brand', color: '#7C3AED' }, { key: 'Growth', color: '#0284C7' }]}
  style={{ width: '100%', maxWidth: 640 }}
  accessibilityLabel="Q3 marketing budget by team and channel"
/>

Visitors from their source onto pages, coloured by source​

linkColor="source" paints each band in its source's colour, so you can follow one source across every page it fed.

Loading…
<SankeyChart
  data={visits}
  sourceKey="from"
  targetKey="to"
  valueKey="n"
  linkColor="source"
  shareLabel={(p) => `${p} of visits`}
  style={{ width: '100%', maxWidth: 640 }}
  accessibilityLabel="This week's visits by source and page"
/>

In real apps​

Guidelines​

Do

Keep a side to five or six nodes. Fold the small ones into "Other"; thin bands are hard to hit and their labels crowd.

Don’t

Don't show flows that don't add up. Both sides should total the same: add "Kept" or "From savings" so the bars match.

Do

Name the share in the tooltip. shareLabel says what the percentage is of: "of money in", "of visits".

Don’t

Don't use it for change over time. A Sankey shows one period's flows; trends belong in a line or bar chart.

Accessibility​

Behaviour
Roleimage, named by accessibilityLabel and a summary of every source and target with its amount and share.
AnnouncedThe tooltip is a live region: the flow or bar under the cursor is read as it changes.
Keyboard (web)Tab focuses the chart (a ring on keyboard focus only); the arrow keys, Home and End step through every bar and flow; Escape clears.
Touch targetBars take touches 8 px to either side, bands across their width (at least 10 px), and tiny flows still draw a 4 px bar and a 2 px band. Press and drag to move between flows.
Reduce motionThe chart appears at once instead of fading in.

API​

SankeyChart​

Also takes style and the theme props.

PropTypeDefaultDescription
dataChartRow[]RequiredOne row per flow.
sourceKeystringRequiredThe row field naming where a flow starts.
targetKeystringRequiredThe row field naming where it ends.
valueKeystringRequiredThe row field with how much it carries.
seriesSeriesConfig[]—Names and colours for nodes, matched by key. Default: the key, and the theme's chart palette in order.
linkColor'target' | 'source''target'Which end's colour a band takes.
shareLabel(percent: string) => string"45% of total"The tooltip's share line.
nodeWidthnumber10The bars' width in px.
nodePaddingnumber8The gap between bars on a side, in px.
heightnumber280The drawing's height.
widthnumbermeasuredA fixed width.
valueFormat'number' | 'compact' | 'currency' | 'percent''number'How amounts read. valueFormatter wins.
currencystring'USD'For valueFormat="currency".
valueFormatter(value: number) => string—Your own amount format.
showTooltipbooleantrueThe readout under the cursor.
renderTooltip(readout: Readout) => ReactNode—Your own tooltip.
onPointSelect(selection: ChartSelection | null) => void—Hears the cursor move to another bar or flow: the place for a haptic tick.
accessibilityLabelstring—What the chart is about, read before the summary.
animatebooleantrueFade in on mount. Skipped when the OS reduces motion.
loadingbooleanfalseA placeholder while data loads.
errorstring—Shown in place of the chart.
emptyLabelstring'No data'Shown when nothing flows.
rtlbooleanthe app's directionLays the chart out right to left: sources on the right.
styleStyleProp<ViewStyle>—The outer view.
theme / design

proportionalFlows​

proportionalFlows(sources, targets) turns two lists of totals ({ key, value }) into rows where every source pours into every target in proportion: for money pooled before it's spent. collectFlows adds up rows with the same ends, and sankeyLayout(flows, width, height, nodeWidth, gap) returns the bars and bands for a drawing of your own.

For AI​

Give this page to an assistant as Markdown, with Copy page at the top, or the whole API in llms-full.txt.

With the Patine MCP server, it asks for get_component_docs({ name: "SankeyChart" })