Skip to documentation content

Sankey Chart

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

Basic Sankey Chart

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

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

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

npm install honestui

Usage

import { SankeyChart, type ChartConfig } from "honestui/charts";
<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.

color='gradient'

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

isLoading='true'

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

API Reference

SankeyChart
PropTypeDefaultDescription
data*TData[]–

One row per link.

config*ChartConfig–

Labels and theme colors keyed by node name.

sourceKey*keyof TData & string–

The field naming each link's source node.

targetKey*keyof TData & string–

The field naming each link's target node.

valueKey*keyof TData & string–

The numeric field that sets each link's width.

nodesstring[]–

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

orienthorizontal|vertical"horizontal"

Flows left to right or top to bottom.

classNamestring–

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

animationbooleantrue

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

isLoadingbooleanfalse

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

ariaLabelstring–

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

onNodeClick(node: SankeyNode) => void–

Fires when a node is selected and Nodes has isClickable.

onLinkClick(link: SankeyLink<TData>) => void–

Fires when a link is selected and Links has isClickable.

chartOptionsRecord<string, unknown>–

Escape hatch merged over the generated ECharts option object.

Nodes
PropTypeDefaultDescription
widthnumber10

Node thickness in pixels.

gapnumber12

Space between nodes in one column.

alignjustify|left|right"justify"

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

radiusnumber2

Node corner radius in pixels.

draggablebooleanfalse

Lets people drag nodes to untangle a dense layout.

isClickablebooleanfalse

Enables the pointer cursor and onNodeClick.

Links
PropTypeDefaultDescription
colorsource|target|gradient"source"

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

opacitynumber0.22

Link opacity at rest. Hovered links grow more opaque.

curvenessnumber0.5

Link curvature from 0 (straight) to 1.

isClickablebooleanfalse

Enables the pointer cursor and onLinkClick.

Labels
PropTypeDefaultDescription
showValuesbooleanfalse

Shows each node's total next to its name.

valueFormatter(value: number) => string–

Formats node totals.

Tooltip
PropTypeDefaultDescription
variantdefault|frosted-glass"default"

Tooltip surface treatment.

roundnesssm|md|lg|xl"lg"

Tooltip corner radius.

positionfixed|variable"variable"

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

valueFormatter(value: number) => string–

Formats values in the tooltip.