# Sankey Chart (/ui/components/react/sankey-chart)

A Sankey chart shows how a volume splits and merges as it moves from 1 set of stages to the next. Like every chart here it is a recipe: [Recharts](https://recharts.github.io) draws it and the [chart layer](/ui/components/react/charts) themes it. Each example below is a complete file to paste and adapt.

## Installation [#installation]

Recharts is the only extra dependency, with `react-is` at the same version as `react`:

```bash
pnpm add recharts react-is   # or: npm install recharts react-is / yarn add recharts react-is / bun add recharts react-is
```

The examples import the chart layer from `@/components/chart`. If your project doesn't have it yet, copy it from the [Charts](/ui/components/react/charts#the-chart-layer) page first.

## Example [#example]

The data is a list of `nodes` and a list of `links` between them, where `source` and `target` are node indexes. Each source node carries a series color as its `fill` and its links take the same color, while the outcome nodes stay neutral in `--foreground-subtle`. `Sankey` is a chart of its own: it takes no `responsive`, and `Chart` sizes it. It also has no entrance animation, so it needs no `useChartMotion`.

```tsx
'use client'

import { Sankey, Tooltip } from 'recharts'
import { Chart, ChartTooltip, chartColors } from '@/components/chart'

const data = {
  nodes: [
    { name: 'Card', fill: chartColors[0] },
    { name: 'Wallet', fill: chartColors[1] },
    { name: 'Bank transfer', fill: chartColors[2] },
    { name: 'Succeeded', fill: 'var(--foreground-subtle)' },
    { name: 'Pending', fill: 'var(--foreground-subtle)' },
    { name: 'Failed', fill: 'var(--foreground-subtle)' },
  ],
  links: [
    { source: 0, target: 3, value: 61200 },
    { source: 0, target: 4, value: 3400 },
    { source: 0, target: 5, value: 4900 },
    { source: 1, target: 3, value: 27800 },
    { source: 1, target: 4, value: 1200 },
    { source: 1, target: 5, value: 1600 },
    { source: 2, target: 3, value: 12600 },
    { source: 2, target: 4, value: 5300 },
    { source: 2, target: 5, value: 900 },
  ],
}

const money = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: 0 })

export default function SankeyChartDefault() {
  return (
    <div className="w-full max-w-2xl">
      <Chart className="h-72">
        <Sankey
          data={data}
          nodePadding={24}
          margin={{ top: 8, right: 96, bottom: 8, left: 8 }}
          label={{ position: 'right', fill: 'var(--foreground)' }}
          aria-label="Payment volume by method and outcome"
        >
          <Tooltip content={<ChartTooltip formatValue={(value) => money.format(value)} />} />
        </Sankey>
      </Chart>
    </div>
  )
}
```

## Accessibility [#accessibility]

- Pass `aria-label` to the chart with what it shows (`"Payment volume by method and outcome"`). It becomes the accessible name of the SVG.
- `label` prints every node's name beside it, so nothing depends on color, and the tooltip names the 2 ends of a link.
- Keep to 3 colored sources. Color the rest by meaning or leave them neutral.
- Nothing animates under reduced motion.
