Sankey diagram reference

Sankey examples

Contents: Use cases, Chart IDs, Minimal spec, Data, Options, Annotations, Sizing, Fixtures, Not for.

Flows from sources to targets in stages (channel to page to purchase, budget to departments, segment moves month to month): rows of source, target and value; node height and ribbon width are the flow. Deterministic crossing reduction, links colored by source or target, small nodes folded into Other, stage-qualified nodes for repeat visits. Type sankey.

Use cases

Chart IDs

One form; its chart ID is sankey.

Minimal spec

{
  "type": "sankey",
  "data": {
    "links": [
      { "source": "search", "target": "product", "value": 420 },
      { "source": "search", "target": "home", "value": 180 },
      { "source": "social", "target": "home", "value": 260 },
      { "source": "email", "target": "product", "value": 140 },
      { "source": "product", "target": "purchase", "value": 210 },
      { "source": "home", "target": "purchase", "value": 90 }
    ],
    "nodes": [
      { "id": "search", "label": "Search" },
      { "id": "social", "label": "Social" },
      { "id": "email", "label": "Email" },
      { "id": "product", "label": "Product page" },
      { "id": "home", "label": "Home page" },
      { "id": "purchase", "label": "Purchase" }
    ],
    "stages": [
      { "id": "channel", "label": "Channel" },
      { "id": "page", "label": "Landing page" },
      { "id": "outcome", "label": "Outcome" }
    ]
  },
  "options": {
    "title": "Search brings most visits that end in a purchase",
    "unit": "k visits",
    "source": "Illustrative data"
  }
}

Data

PathTypeRequiredMeaning
linksarrayyesFlows as rows of source, target and value: the shape of a GROUP BY source, target result. Columns follow from the graph: sources left, ends right. A cycle is refused unless stages separate the visits.
links[].sourcestringyesId of the node the flow leaves.
links[].targetstringyesId of the node the flow enters.
links[].valuenumberyesThe flow, 0 or more: the link width. A zero link draws nothing and warns sankey-zero-link; a negative value is refused. Links with the same ends (and stages) add up.
links[].sourceStagestringStage of the source node. With stages, a node is the pair (stage, id): 'gold' in '2026-01' and 'gold' in '2026-02' are two nodes that share the label and color of 'gold'. Set both stages on every link or on none.
links[].targetStagestringStage of the target node; it comes after sourceStage in the stage order and may skip stages.
nodesarrayLabels and colors per node id, in the order the nodes take under order "data" and the order colors follow. A link may name an id this list does not hold.
nodes[].idstringyesNode id that links name in source and target.
nodes[].labelstringName beside the node; defaults to the id.
nodes[].colorRolestringTheme color role of the node and the links it colors. One of good, bad, warn, neutral, neutralLight, highlight, total, others; series-N for step N of the theme ramp, 1-based (series-2 is color.series[1]); or status-<key> for a theme status color. A hex color goes in fill.
nodes[].fillstringAuthored fill of the node and the links it colors.
stagesarrayStage order and column headers. With stage-qualified links it sets the stage order. Without, it names the drawn columns left to right and must have one entry per column.
stages[].idstringyesStage id that links name in sourceStage and targetStage.
stages[].labelstringHeader above the stage column; defaults to the id.

Options

PathTypeValuesDefaultMeaning
linkColorstring'source', 'target'Which end's node color a ribbon takes. Unset: every node and ribbon draws neutral, and a node with fill, colorRole or a highlight colors the ribbons it touches. 'source' shows where flows come from and 'target' where they go, each with one palette step per node; with a highlight, only the highlighted nodes keep a color. Nodes that color no link draw in the neutral mark color. Ribbons are translucent so crossings and node bars show through: on a light page the alpha rises from surface.ribbonAlpha (default 0.35) until a ribbon reaches the 1.4:1 mark floor; on a dark page it stays at surface.ribbonAlpha, under 3:1 against the page, and the node bars and values carry the flow.
orderstring'flow', 'data''flow' orders the nodes of each column for the fewest weighted ribbon crossings. 'data' keeps the order of data.nodes, then first seen in links. Default 'flow', and 'data' when stage-qualified ids repeat across stages, so segments keep one order every month.
otherfalse | objectfalse (or another value of its type)Small nodes folded into one Other node per column, so a long tail stays readable; the note lists every folded node with its value. A column folds only when at least two nodes qualify. The Other node is as tall as its members together, so each column keeps its total. Default { share: 0.02 } without stages; off with stage-qualified links, where an object folds an id in every stage or in none. false keeps every node.
other.sharenumberFold nodes under this share of their column's total; default 0.02.
other.labelstringName of the folded node; default strings.others, else 'Others'.
nodeValuestring | false'value', 'share', 'value-share', falseWhat a node prints in bold after its name: 'value' (default), 'share' of its column's total, or 'value-share' as "420 (38%)". A percent format applies to the shares. false prints the name only; the marks, hover and records keep the value, and linkValue still decides the ribbon values.
columnOverridesobjectSettings per generated column. Ids: first, last.
columnOverrides.*.widthnumberTrack width in px. It beats the width the type would pick.
linkValuestring'none', 'large''large'Flow values on the ribbons: 'large' (default) prints the value of every ribbon at least one line high at its arriving end, right aligned to the next bar; thinner ribbons print nothing, and a value that would cover a node label is left out. 'none' prints node values only.

Plus the shared options. This type does not accept detailFields, labels, labelPosition, valueAxis, story, hatchStrength, rounding, annotations. This type ignores animate, debug, rowLabels, categoryAxis, categoryLabels, secondaryAxis, sort, topN, bandFraction, legend, valueAxis.show, valueAxis.gridlines with an option-ignored warning.

Annotations

This type takes no annotations.

Sizing

Floor 280 × 270 px; fit fill.

Below the floor a render is refused with size-below-floor and the pixels it needs. measure returns the natural and comfortable size for a given spec; see Sizing in the manual.

Fixtures

IDKindUse case
channel-journeysexampleChannel to landing page to outcome: stage headers, two small channels folded into Others and listed in the note, Purchase highlighted
channel-journeys-node-valuesexampleChannel journeys with linkValue none: node values only, no value on the ribbons
budget-departmentsexampleBudget to departments to cost types, links colored by target
segment-migrationexampleCustomers moving between segments month to month: stage-qualified nodes, one segment order in every month
sales-stagestortureSix stages with drop-outs that skip columns as long links
long-names-phonetortureLong node names on a 280 px phone card: names wrap and break with a hyphen
unbalanced-nodestortureNodes whose inflow and outflow differ, duplicate rows that add up and a zero row
no-node-valuesexampleNodes print their names only
column-overridesexampleAuthored widths for the label gutters of the first and last stage

Not for

Flows that loop back without stages (refused as a cycle; give links sourceStage and targetStage), or parts of one total (use treemap or bar). Pairwise rows do not say which channel a purchase came from once flows merge at a page: for that, build path-qualified nodes from journey data.