# Sankey Chart

> A composable sankey diagram for showing how quantities flow between stages, sources, and outcomes.

Source: https://www.honestui.com/docs/charts/sankey-chart/static

### Basic Sankey Chart

```tsx
"use client";

import { SankeyChart, type ChartConfig } from "honestui/charts";

// Scenario: Where signups come from and where they end up
const data = [
  { from: "Search", to: "Docs", visitors: 4200 },
  { from: "Search", to: "Pricing", visitors: 1900 },
  { from: "Social", to: "Blog", visitors: 2600 },
  { from: "Social", to: "Pricing", visitors: 700 },
  { from: "Referral", to: "Pricing", visitors: 1500 },
  { from: "Referral", to: "Docs", visitors: 600 },
  { from: "Docs", to: "Signed up", visitors: 1700 },
  { from: "Docs", to: "Left", visitors: 3100 },
  { from: "Blog", to: "Signed up", visitors: 500 },
  { from: "Blog", to: "Left", visitors: 2100 },
  { from: "Pricing", to: "Signed up", visitors: 2300 },
  { from: "Pricing", to: "Left", visitors: 1800 },
];

const chartConfig = {
  Search: { label: "Search", colors: { light: ["#2563eb"], dark: ["#3b82f6"] } },
  Social: { label: "Social", colors: { light: ["#db2777"], dark: ["#ec4899"] } },
  Referral: { label: "Referral", colors: { light: ["#d97706"], dark: ["#f59e0b"] } },
  "Signed up": { label: "Signed up", colors: { light: ["#059669"], dark: ["#10b981"] } },
  Left: { label: "Left", colors: { light: ["#a1a1aa"], dark: ["#52525b"] } },
} satisfies ChartConfig;

export function ExampleSankeyChart() {
  return (
    <SankeyChart
      data={data}
      config={chartConfig}
      sourceKey="from"
      targetKey="to"
      valueKey="visitors"
      className="h-full w-full p-4"
    >
      <SankeyChart.Labels />
      <SankeyChart.Tooltip />
      <SankeyChart.Links />
      <SankeyChart.Nodes />
    </SankeyChart>
  );
}

```

## Overview [#overview]

Use a sankey diagram when the question is where something goes: which traffic sources lead to signups, how a budget splits into spending, or how energy moves through a system. Each link's width is proportional to its value, and each node's height is the larger of what flows in and out of it. Unlike a funnel, flows can split, merge, and skip columns.

## Anatomy [#anatomy]

`SankeyChart` takes one row per link and derives the nodes from the source and target names. Add `Nodes` to control node width, spacing, and column alignment, `Links` for link color, opacity, and curvature, `Labels` for node names and totals, and `Tooltip` for a node's inflow and outflow or a link's value and share of its source.

A node with its own `config` entry takes that color. A node without one borrows the color of its largest inflow, so a flow keeps its identity until it reaches a node that defines its own color. Links are tinted by their source at low opacity, and hovering a node or link keeps only its neighbourhood in focus.

## Accessibility [#accessibility]

When `ariaLabel` is omitted, the generated name counts the flows and nodes, names the sources, and lists the largest flows. Link width carries the value, and colors only group related flows, so the diagram still reads without color. The tooltip and hover focus are pointer-operated; give people a table of flows when exact values matter.

## Installation [#installation]

<CommandBlock commands="[&#x22;honestui&#x22;]" />

## Usage [#usage]

```tsx
import { SankeyChart, type ChartConfig } from "honestui/charts";
```

```tsx
<SankeyChart
  data={data}
  config={chartConfig}
  sourceKey="from"
  targetKey="to"
  valueKey="visitors"
>
  <SankeyChart.Labels />
  <SankeyChart.Tooltip />
  <SankeyChart.Links />
  <SankeyChart.Nodes />
</SankeyChart>
```

Links must not form a cycle, and a node cannot link to itself. Self-links and zero values are skipped. Labels on the last column sit inside the diagram so they never run off the edge.

### Gradient Links [#gradient-links]

### color='gradient'

```tsx
"use client";

import { SankeyChart, type ChartConfig } from "honestui/charts";

// Scenario: Monthly household budget
const data = [
  { source: "Salary", target: "Income", amount: 6200 },
  { source: "Freelance", target: "Income", amount: 1400 },
  { source: "Income", target: "Housing", amount: 2400 },
  { source: "Income", target: "Living", amount: 2100 },
  { source: "Income", target: "Savings", amount: 1900 },
  { source: "Income", target: "Taxes", amount: 1200 },
  { source: "Living", target: "Groceries", amount: 900 },
  { source: "Living", target: "Transport", amount: 600 },
  { source: "Living", target: "Fun", amount: 600 },
];

const chartConfig = {
  Salary: { label: "Salary", colors: { light: ["#0d9488"], dark: ["#14b8a6"] } },
  Freelance: { label: "Freelance", colors: { light: ["#0891b2"], dark: ["#22d3ee"] } },
  Income: { label: "Income", colors: { light: ["#0f766e"], dark: ["#2dd4bf"] } },
  Housing: { label: "Housing", colors: { light: ["#e11d48"], dark: ["#fb7185"] } },
  Living: { label: "Living", colors: { light: ["#ea580c"], dark: ["#fb923c"] } },
  Savings: { label: "Savings", colors: { light: ["#16a34a"], dark: ["#4ade80"] } },
  Taxes: { label: "Taxes", colors: { light: ["#71717a"], dark: ["#a1a1aa"] } },
} satisfies ChartConfig;

const usd = (value: number) => `$${value.toLocaleString()}`;

export function ExampleSankeyChart() {
  return (
    <SankeyChart
      data={data}
      config={chartConfig}
      sourceKey="source"
      targetKey="target"
      valueKey="amount"
      nodes={["Salary", "Freelance", "Income", "Housing", "Living", "Savings", "Taxes"]}
      className="h-full w-full p-4"
    >
      <SankeyChart.Labels showValues valueFormatter={usd} />
      <SankeyChart.Tooltip valueFormatter={usd} />
      <SankeyChart.Links color="gradient" opacity={0.28} />
      <SankeyChart.Nodes width={12} align="left" />
    </SankeyChart>
  );
}

```

Gradient links blend from the source color to the target color, which helps when both ends of each flow matter. This example also shows totals next to each label, left-aligns the columns, and passes `nodes` to fix the node order.

### Loading State [#loading-state]

### isLoading='true'

```tsx
"use client";

import { SankeyChart, type ChartConfig } from "honestui/charts";

const chartConfig = {
  Search: { label: "Search", colors: { light: ["#2563eb"], dark: ["#3b82f6"] } },
} satisfies ChartConfig;

export function LoadingSankeyChart() {
  return (
    <SankeyChart
      data={[]}
      config={chartConfig}
      sourceKey="from"
      targetKey="to"
      valueKey="visitors"
      isLoading
      className="h-full w-full p-4"
    >
      <SankeyChart.Labels />
      <SankeyChart.Tooltip />
      <SankeyChart.Nodes />
    </SankeyChart>
  );
}

```

Pass `isLoading` to reserve the layout with a neutral placeholder diagram and the same loading treatment as the other Honest UI charts.

## API Reference [#api-reference]

<ApiHeading>
  SankeyChart
</ApiHeading>


  ### `data`

type: `TData[]`

One row per link.

  ### `config`

type: `ChartConfig`

Labels and theme colors keyed by node name.

  ### `sourceKey`

type: `keyof TData & string`

The field naming each link's source node.

  ### `targetKey`

type: `keyof TData & string`

The field naming each link's target node.

  ### `valueKey`

type: `keyof TData & string`

The numeric field that sets each link's width.

  ### `nodes`

type: `string[]`

Node order within columns. Nodes not listed follow in order of appearance.

  ### `orient`

type: `&#x22;horizontal&#x22; | &#x22;vertical&#x22;` · default: `&#x22;horizontal&#x22;`

Flows left to right or top to bottom.

  ### `className`

type: `string`

Additional CSS classes for the chart container. Give the chart an explicit height.

  ### `animation`

type: `boolean` · default: `true`

Enables the intro animation. Reduced-motion preferences disable it automatically.

  ### `isLoading`

type: `boolean` · default: `false`

Replaces the data with a neutral placeholder diagram and a progress label.

  ### `ariaLabel`

type: `string`

Accessible name for the canvas chart. A summary of the largest flows is generated when omitted.

  ### `onNodeClick`



void">
    Fires when a node is selected and `Nodes` has `isClickable`.

  ### `onLinkClick`



) => void">
    Fires when a link is selected and `Links` has `isClickable`.

  ### `chartOptions`



">
    Escape hatch merged over the generated ECharts option object.


<ApiHeading>
  Nodes
</ApiHeading>


  ### `width`

type: `number` · default: `10`

Node thickness in pixels.

  ### `gap`

type: `number` · default: `12`

Space between nodes in one column.

  ### `align`

type: `&#x22;justify&#x22; | &#x22;left&#x22; | &#x22;right&#x22;` · default: `&#x22;justify&#x22;`

Spreads terminal nodes to the last column, or packs columns to one side.

  ### `radius`

type: `number` · default: `2`

Node corner radius in pixels.

  ### `draggable`

type: `boolean` · default: `false`

Lets people drag nodes to untangle a dense layout.

  ### `isClickable`

type: `boolean` · default: `false`

Enables the pointer cursor and `onNodeClick`.


<ApiHeading>
  Links
</ApiHeading>


  ### `color`

type: `&#x22;source&#x22; | &#x22;target&#x22; | &#x22;gradient&#x22;` · default: `&#x22;source&#x22;`

Tints links by their source, their target, or a blend of both.

  ### `opacity`

type: `number` · default: `0.22`

Link opacity at rest. Hovered links grow more opaque.

  ### `curveness`

type: `number` · default: `0.5`

Link curvature from 0 (straight) to 1.

  ### `isClickable`

type: `boolean` · default: `false`

Enables the pointer cursor and `onLinkClick`.


<ApiHeading>
  Labels
</ApiHeading>


  ### `showValues`

type: `boolean` · default: `false`

Shows each node's total next to its name.

  ### `valueFormatter`



string">
    Formats node totals.


<ApiHeading>
  Tooltip
</ApiHeading>


  ### `variant`

type: `&#x22;default&#x22; | &#x22;frosted-glass&#x22;` · default: `&#x22;default&#x22;`

Tooltip surface treatment.

  ### `roundness`

type: `&#x22;sm&#x22; | &#x22;md&#x22; | &#x22;lg&#x22; | &#x22;xl&#x22;` · default: `&#x22;lg&#x22;`

Tooltip corner radius.

  ### `position`

type: `&#x22;fixed&#x22; | &#x22;variable&#x22;` · default: `&#x22;variable&#x22;`

Pins the tooltip to the top or lets it follow the pointer.

  ### `valueFormatter`



string">
    Formats values in the tooltip.
