Phi
Sankey Chart
@dicehub/phiv1.0.0-beta.1

Sankey Chart

A Sankey diagram component for visualizing flow data between nodes.

A simple Sankey diagram showing flow between source and target nodes.

<SankeyChart
  :echarts="echarts"
  :nodes="nodes"
  :links="links"
  :height="350"
/>

Installation

SankeyChart requires ECharts with the Sankey chart module registered.

pnpm add echarts

Imports

import { SankeyChart, ChartPalette, type SankeyTooltipParams } from "@dicehub/phi/components/chart";

Usage

<script setup lang="ts">
import { ChartPalette, SankeyChart } from "@dicehub/phi/components/chart";
import * as echarts from "echarts/core";
import { SankeyChart as EChartsSankeyChart } from "echarts/charts";
import { TooltipComponent } from "echarts/components";
import { CanvasRenderer } from "echarts/renderers";

echarts.use([CanvasRenderer, EChartsSankeyChart, TooltipComponent]);

const nodes = [
  { name: "Users", value: 103600, color: ChartPalette.categorical(0) },
  { name: "Devices", value: 50800, color: ChartPalette.categorical(1) },
  { name: "Apps", value: 122600, color: ChartPalette.categorical(2) },
  { name: "Tunnels", value: 31800, color: ChartPalette.categorical(3) },
];

const links = [
  { source: 0, target: 2, value: 80000 },
  { source: 0, target: 3, value: 23600 },
  { source: 1, target: 2, value: 42600 },
  { source: 1, target: 3, value: 8200 },
];
</script>

<template>
  <SankeyChart
    :echarts="echarts"
    :nodes="nodes"
    :links="links"
    :height="350"
  />
</template>

Examples

Basic Sankey

A simple Sankey diagram showing flow between source and target nodes.

<SankeyChart :echarts="echarts" :nodes="nodes" :links="links" :height="350" />

Multi-Level Flow

Sankey diagrams can show multiple levels of flow through intermediate nodes.

<SankeyChart
  :echarts="echarts"
  :nodes="nodes"
  :links="links"
  :height="350"
  :node-width="20"
  :node-padding="15"
/>

Full-Width Layout

Use left and right to control horizontal padding inside the chart.

<SankeyChart
  :echarts="echarts"
  :nodes="nodes"
  :links="links"
  :height="350"
  :left="0"
  :right="0"
/>

Rich Tooltips

Use tooltipFormatter for full control over tooltip content.

<SankeyChart
  :echarts="echarts"
  :nodes="nodes"
  :links="links"
  :tooltip-formatter="formatTooltip"
/>

Interactive

Use node and link click handlers to drive selection.

<SankeyChart
  :echarts="echarts"
  :nodes="nodes"
  :links="links"
  @node-click="handleNodeClick"
  @link-click="handleLinkClick"
/>

Drill-Down Filtering

Click a node or link to filter the chart and expose a focused flow view.

<SankeyChart
  :echarts="echarts"
  :nodes="filteredNodes"
  :links="filteredLinks"
  @node-click="handleNodeClick"
  @link-click="handleLinkClick"
/>

Inline Label Layout

Use inline labels when stacked labels would overlap.

<SankeyChart
  :echarts="echarts"
  :nodes="nodes"
  :links="links"
  node-label-layout="inline"
/>

API Reference

PropTypeDefaultDescription
echartstypeof echarts-ECharts core instance with Sankey, tooltip, and renderer modules registered.
nodesSankeyNodeData[]-Nodes in the Sankey diagram.
linksSankeyLinkData[]-Links connecting node indexes.
heightnumber400Chart height in pixels.
showNodeValuesbooleanautoShows node values when any node has a value.
nodeLabelLayout"stacked" | "inline""stacked"Controls whether node values stack above labels or render inline.
formatValue(value: number) => stringtoLocaleString()Formats node and link values.
tooltipFormatter(params: SankeyTooltipParams) => string-Optional trusted HTML tooltip formatter.
nodeWidthnumber8Width of each Sankey node.
nodePaddingnumber10Vertical gap between nodes.
showTooltipbooleantrueControls tooltip visibility.
defaultNodeColorstring-Fallback color for nodes without explicit colors.
leftnumber | string-Left padding of the Sankey layout.
rightnumber | string-Right padding of the Sankey layout.
linkColor"gradient" | "gray""gradient"Controls whether links blend from source color or use flat gray.
linkOpacitynumber0.5Opacity for gradient links.
classNamestring-Optional class passed to the chart element.
isDarkModebooleanfalseInitializes ECharts with dark mode and dark chart colors.
onNodeClick(node: SankeyNodeData) => void-Called when a node is clicked.
onLinkClick(link: SankeyLinkData) => void-Called when a link is clicked.