Sankey chart
Since 0.1.0-alpha.22Use a Sankey to show where an amount comes from and where it goes, such as a budget from income to spending. Many small flows make it cluttered, so combine them into one. For a single process that people drop out of, use a funnel.
Flows between stages
Give SankeyChart the flows as Items, with From, To and Value for each, and a Title, here a household's pay through its budget.
Static
Preview
| From | To | Amount | Share of From |
|---|---|---|---|
| Salary | Budget | $4,200 | 100% |
| Freelance | Budget | $800 | 100% |
| Budget | Housing | $2,000 | 40% |
| Budget | Savings | $1,000 | 20% |
| Budget | Food | $800 | 16% |
| Budget | Leisure | $750 | 15% |
| Budget | Transport | $450 | 9.0% |
Code
@* A household's take-home pay for October, through its budget into what it went on. *@
<SankeyChart Items="_flows"
From="f => f.From"
To="f => f.To"
Value="f => f.Amount"
ValueFormat="C0"
LinkColor="SankeyLinkColor.Gradient"
Title="October's budget" />
{
private record Flow(string From, string To, decimal Amount);
private readonly Flow[] _flows =
[
new("Salary", "Budget", 4200),
new("Freelance", "Budget", 800),
new("Budget", "Housing", 2000),
new("Budget", "Savings", 1000),
new("Budget", "Food", 800),
new("Budget", "Leisure", 750),
new("Budget", "Transport", 450),
];
}Add this example to a page with the izzy CLI:
izzy add component SankeyChart --at <file>:<line>Nodes come from the names in From and To, and each is as tall as what flows through it. A flow takes the color of the node it starts from; LinkColor="SankeyLinkColor.Gradient" blends it into the color of where it goes.
Hover a flow or a node for its values, or Tab to the chart and move from node to node with the arrow keys.
Node order and gray flows
To keep nodes in the order the items name them, set NodeOrder to Data: here the sources stay largest first and the outcome Signed up stays on top. LinkColor="SankeyLinkColor.Neutral" draws every flow in one gray.
Static
Preview
| From | To | Visits | Share of From |
|---|---|---|---|
| Search | Home page | 6,200 | 53% |
| Search | Pricing | 2,100 | 18% |
| Search | Blog | 3,400 | 29% |
| Social | Home page | 1,800 | 41% |
| Social | Blog | 2,600 | 59% |
| Pricing | 1,500 | 68% | |
| Home page | 700 | 32% | |
| Referral | Pricing | 900 | 60% |
| Referral | Home page | 600 | 40% |
| Home page | Signed up | 1,100 | 12% |
| Home page | Didn't sign up | 8,200 | 88% |
| Pricing | Signed up | 1,300 | 29% |
| Pricing | Didn't sign up | 3,200 | 71% |
| Blog | Signed up | 300 | 5.0% |
| Blog | Didn't sign up | 5,700 | 95% |
Code
@* A month of visits to a product's site: where they came from, the page they landed on, and
whether they signed up. *@
<SankeyChart Items="_paths"
From="p => p.From"
To="p => p.To"
Value="p => p.Visits"
NodeOrder="SankeyOrder.Data"
LinkColor="SankeyLinkColor.Neutral"
Title="Visits to sign-ups, October">
<SankeyNode Name="Signed up" Color="var(--ib-color-success)" />
<SankeyNode Name="Didn't sign up" Color="var(--ib-color-neutral)" />
</SankeyChart>
{
private record Visit(string From, string To, int Visits);
private readonly Visit[] _paths =
[
new("Search", "Home page", 6200),
new("Search", "Pricing", 2100),
new("Search", "Blog", 3400),
new("Social", "Home page", 1800),
new("Social", "Blog", 2600),
new("Email", "Pricing", 1500),
new("Email", "Home page", 700),
new("Referral", "Pricing", 900),
new("Referral", "Home page", 600),
new("Home page", "Signed up", 1100),
new("Home page", "Didn't sign up", 8200),
new("Pricing", "Signed up", 1300),
new("Pricing", "Didn't sign up", 3200),
new("Blog", "Signed up", 300),
new("Blog", "Didn't sign up", 5700),
];
}One gray for every flow suits a diagram with many nodes, and leaves color for the nodes that matter, here Signed up.
Node and flow colors
Color a node by what it means with a SankeyNode, such as profit in green and costs in red. LinkColor="SankeyLinkColor.Target" colors each flow by where it goes, and Values writes each node's amount after its name.
Static
Preview
| From | To | Millions | Share of From |
|---|---|---|---|
| Licenses | Revenue | $420M | 100% |
| Subscriptions | Revenue | $260M | 100% |
| Services | Revenue | $180M | 100% |
| Revenue | Gross profit | $660M | 77% |
| Revenue | Cost of revenue | $200M | 23% |
| Cost of revenue | Hosting | $130M | 65% |
| Cost of revenue | Support | $70M | 35% |
| Gross profit | Operating profit | $260M | 39% |
| Gross profit | Operating expenses | $400M | 61% |
| Operating expenses | R&D | $180M | 45% |
| Operating expenses | Sales & marketing | $160M | 40% |
| Operating expenses | Admin | $60M | 15% |
| Operating profit | Net profit | $205M | 79% |
| Operating profit | Tax | $55M | 21% |
Code
@* A software company's year, in millions: revenue by segment, through costs, to net profit. *@
<SankeyChart Items="_flows"
From="f => f.From"
To="f => f.To"
Value="f => f.Millions"
ValueFormat="$#,##0M"
LinkColor="SankeyLinkColor.Target"
Values="true"
Height="Length.Rem(22)"
Title="Income statement, 2025">
foreach (var name in _segments)
{
<SankeyNode Name="name" Color="var(--ib-color-neutral)" />
}
foreach (var name in _profit)
{
<SankeyNode Name="name" Color="var(--ib-color-success)" />
}
foreach (var name in _costs)
{
<SankeyNode Name="name" Color="var(--ib-color-danger)" />
}
</SankeyChart>
{
private record Flow(string From, string To, decimal Millions);
private readonly string[] _segments = ["Licenses", "Subscriptions", "Services", "Revenue"];
private readonly string[] _profit = ["Gross profit", "Operating profit", "Net profit"];
private readonly string[] _costs =
["Cost of revenue", "Hosting", "Support", "Operating expenses", "R&D", "Sales & marketing", "Admin", "Tax"];
private readonly Flow[] _flows =
[
new("Licenses", "Revenue", 420),
new("Subscriptions", "Revenue", 260),
new("Services", "Revenue", 180),
new("Revenue", "Gross profit", 660),
new("Revenue", "Cost of revenue", 200),
new("Cost of revenue", "Hosting", 130),
new("Cost of revenue", "Support", 70),
new("Gross profit", "Operating profit", 260),
new("Gross profit", "Operating expenses", 400),
new("Operating expenses", "R&D", 180),
new("Operating expenses", "Sales & marketing", 160),
new("Operating expenses", "Admin", 60),
new("Operating profit", "Net profit", 205),
new("Operating profit", "Tax", 55),
];
}Every node with no flows out sits in the last column, so Hosting and Support end beside Net profit. NodeAlign changes that: Start keeps each node as far left as its flows allow.
Details
Each item is one flow. Nodes come from the flows' names, so there's no list of them; a SankeyNode inside the chart gives one its own color or label. Flows between the same two nodes add up; zero, negative and missing values are left out. A node is as tall as the larger of what flows in and out of it. Flows can't loop back to a node they came from. Columns follow the flows (NodeAlign); within a column the nodes move to cross as few flows as they can, or keep the items' order (NodeOrder). Each node's name sits beside its bar; Values adds what flows through it. A Sankey reads best with a few stages and up to about 30 nodes; when the flows are of similar sizes, or only their totals matter, a stacked bar chart reads better.
Parts
Written inside SankeyChart. The API page lists their parameters.
SankeyNode: one node of aSankeyChart<T>that needs its own color or label, such as<SankeyNode Name="Net profit" Color="var(--ib-color-success)" />.
Mode support
| Feature | Static | Interactive |
|---|---|---|
| Nodes worked out from the flows' names, with no list of nodes to keep | Yes | Yes |
| Columns by the flows, with every end node in the last column, or each node as far left or right as it can go | Yes | Yes |
| Nodes ordered to cross as few flows as they can, or kept in the items' order | Yes | Yes |
| Flows colored by where they start, where they end, a blend of the two, or one gray | Yes | Yes |
| Each node's name beside its bar, inside the plot, and its value with Values (on a phone, the name only) | Yes | Yes |
| A node's own color or label with SankeyNode | Yes | Yes |
| A table of every flow and its share of its node, in a "Show data" disclosure | Yes | Yes |
| Tooltips on flows and nodes, the flow (or a node's flows) drawn stronger, on hover and from the keyboard | Yes | Yes |
Static: static server-side rendering, with no circuit and no WebAssembly. Interactive: Server, WebAssembly or Auto.
Without JavaScript
Every page starts as plain HTML: before IzzyBlazor's script loads on a static page, while an interactive page prerenders, and with JavaScript off.
- Tooltips on flows and nodes, the flow (or a node's flows) drawn stronger, on hover and from the keyboard: waits for the script
Accessibility
- The chart is a figure captioned by
Title, or named by a heading on the page withTitledBy. - The diagram is one image named by the caption, described by its count of flows and nodes.
- "Show data" under the chart opens a table of every flow: from, to, value and its share of what leaves its node (
DataTable). - Nodes are told apart by their labels and places, not only by color.
- With IzzyBlazor's script, the diagram is one Tab stop: the arrow keys move from node to node and say each one's flows in and out.
Keyboard navigation
On the diagram
| Press this key | To do this |
|---|---|
| Down or Up | Move to the next or previous node in the column |
| Right or Left | Move to the nearest node in the next or previous column |
| Home or End | Go to the first or last node |
| Escape | Hide the tooltip |
Parameters
| Prop | Type | Default |
|---|---|---|
RefreshHow often the chart reads its data again, at least a second, such as Refresh="TimeSpan.FromSeconds(30)". | TimeSpan? | |
RefreshFromOn a static page with Refresh: a lighter page to fetch than this one, which renders the same chart with the same id. | string? | |
ItemsThe flows, one item each: where it comes from, where it goes and how much. | IEnumerable<TItem>? | Required |
FromThe node each flow comes from, such as f => f.From. | Expression<Func<TItem, object?>> | Required |
ToThe node each flow goes to, such as f => f.To. | Expression<Func<TItem, object?>> | Required |
ValueHow much each flow carries, such as f => f.Amount: any number. | Expression<Func<TItem, object?>> | Required |
TitleThe chart's title, such as "October's budget", shown above it as its caption. | string? | |
HideTitleHides the title, which still names the chart for screen readers. | bool | false |
DownloadShows a button across from the title that saves the chart as a PNG, named after its title, in the color scheme on screen. | bool | false |
TitleAlignWhere the title sits: at the start by default (the left, in a left-to-right page); ChartAlign.Center or ChartAlign.End. | ChartAlign | ChartAlign.Start |
TitledByThe id of a heading already on the page that titles the chart, such as a card's, in place of Title: the chart takes its name from it and shows no title of its own. | string? | |
ValueFormatA .NET format string for the values, such as C0 or N0: on the labels, in the tooltips and the table. | string? | |
NodeAlignWhich column each node goes in: SankeyAlign.Justify (the default) puts every node with no flows out in the last column; SankeyAlign.Start keeps each as far left as it can, SankeyAlign.End as far right, and SankeyAlign.Center puts a node with no flows in just before where it flows, and the rest as Start does. | SankeyAlign | SankeyAlign.Justify |
NodeOrderThe nodes' order in each column: SankeyOrder.Auto (the default) moves them to cross as few flows as it can; SankeyOrder.Data keeps the order the items first name them in, top to bottom. | SankeyOrder | SankeyOrder.Auto |
LinkColorWhat colors each flow: SankeyLinkColor.Source, the node it comes from (the default); SankeyLinkColor.Target, the node it goes to; SankeyLinkColor.Gradient, a blend of the two; or SankeyLinkColor.Neutral, one gray. | SankeyLinkColor | SankeyLinkColor.Source |
LabelsWrites each node's name beside its bar, inside the diagram. | bool | true |
ValuesWrites each node's value after its name, such as "Housing $1,700". | bool | false |
HeightThe diagram's height. | Length? | computed |
PaletteThe nodes' colors in order: Colors (the theme's eight, the default, repeating past eight), Shades of one color, or your own with Of. | ChartPalette? | |
TooltipA tooltip for the flow or node under the pointer, and the arrow keys from node to node, each saying its flows (with IzzyBlazor's script; with JavaScript off, a hover title). | bool | true |
DataTableThe flows as a table: by default behind a "Show data" button that opens it over the chart; ChartDataTable.Collapsed puts it in a disclosure under the chart. | ChartDataTable | ChartDataTable.Popover |
ChildContentSankeyNodes for nodes that need their own color or label, and a ChartTooltip<T> for your own flow tooltips. | RenderFragment? | |
OnRefreshOn an interactive page with Refresh: raised at each interval, to load new data. | EventCallback |
Plus 17 item props and 4 common props.
Full APISee also
- FunnelChart: shows how many make it through each step of a checkout, a sign-up or a sales pipeline, and where the most are lost.
- Chart: draws a chart on the server from a list of items, with axes, value labels, reference lines, trends and a table of the values, for every chart type.