SankeyChart

Sankey diagram component

Usage

SankeyChart is based on the Sankey recharts component. It visualizes flow between nodes where the width of each link is proportional to the flow value:

import { SankeyChart } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return <SankeyChart data={data} />;
}

Data

Pass an object with nodes and links arrays to the data prop. Each link references its source and target nodes by their zero-based index in the nodes array. Links must not form a cycle:

import { SankeyChartData } from '@mantine/charts';

export const data: SankeyChartData = {
  nodes: [{ name: 'Visitors' }, { name: 'Signups' }, { name: 'Purchases' }],
  links: [
    { source: 0, target: 1, value: 100 },
    { source: 1, target: 2, value: 30 },
  ],
};

Node color

Set color on a node in the data to change its color. Theme colors and any valid CSS color are accepted:

import { SankeyChart } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return <SankeyChart data={data} />;
}

Custom colors

Use colors prop to set colors for nodes that do not have color. Colors repeat when there are more nodes than colors:

import { SankeyChart } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return (
    <SankeyChart
      data={data}
      colors={['indigo.6', 'cyan.6', 'teal.6', 'orange.6', 'red.6']}
    />
  );
}

Node and link color

By default, each link has the color of its source node. Set linkColor prop to use one color for all links. Set nodeColor prop to use one color for all nodes that do not have color:

import { SankeyChart } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return <SankeyChart data={data} nodeColor="indigo.6" linkColor="gray.6" />;
}

Node width and padding

Use nodeWidth to control the width of each node and nodePadding to control the spacing between nodes:

import { SankeyChart } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return <SankeyChart data={data} nodeWidth={20} nodePadding={20} />;
}

Link opacity

Use linkOpacity prop to control the opacity of links between nodes:

import { SankeyChart } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return <SankeyChart data={data} linkOpacity={0.2} />;
}

Value formatter

Use valueFormatter to format values in node labels and in the tooltip:

import { SankeyChart } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return (
    <SankeyChart
      data={data}
      valueFormatter={(value) => new Intl.NumberFormat('en-US').format(value)}
    />
  );
}

Disable tooltip

To disable the tooltip, set withTooltip={false}:

import { SankeyChart } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return <SankeyChart data={data} withTooltip={false} />;
}