Skip to content
IzzyBlazor

Enter all results ↑ ↓ move Esc close

Sankey chart

Since 0.1.0-alpha.22
Shows where an amount comes from and where it goes, such as a budget from income to spending.

Use 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

October's budget
Arrow keys move between nodes; Escape hides the tooltip.7 flows between 8 nodes, left to right

Code

Usage.razor
@* 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" />

@code {
    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:

bash
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

Visits to sign-ups, October
Arrow keys move between nodes; Escape hides the tooltip.15 flows between 9 nodes, left to right

Code

Paths.razor
@* 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>

@code {
    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

Income statement, 2025
Arrow keys move between nodes; Escape hides the tooltip.14 flows between 15 nodes, left to right

Code

IncomeStatement.razor
@* 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>

@code {
    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 a SankeyChart<T> that needs its own color or label, such as <SankeyNode Name="Net profit" Color="var(--ib-color-success)" />.

Mode support

What works in each mode, Sankey chart
FeatureStaticInteractive
Nodes worked out from the flows' names, with no list of nodes to keepYesYes
Columns by the flows, with every end node in the last column, or each node as far left or right as it can goYesYes
Nodes ordered to cross as few flows as they can, or kept in the items' orderYesYes
Flows colored by where they start, where they end, a blend of the two, or one grayYesYes
Each node's name beside its bar, inside the plot, and its value with Values (on a phone, the name only)YesYes
A node's own color or label with SankeyNodeYesYes
A table of every flow and its share of its node, in a "Show data" disclosureYesYes
Tooltips on flows and nodes, the flow (or a node's flows) drawn stronger, on hover and from the keyboardYesYes

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 with TitledBy.
  • 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

SankeyChart keys, On the diagram
Press this keyTo do this
Down or UpMove to the next or previous node in the column
Right or LeftMove to the nearest node in the next or previous column
Home or EndGo to the first or last node
EscapeHide the tooltip

Parameters

SankeyChart parameters
PropTypeDefault
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.boolfalse
DownloadShows a button across from the title that saves the chart as a PNG, named after its title, in the color scheme on screen.boolfalse
TitleAlignWhere the title sits: at the start by default (the left, in a left-to-right page); ChartAlign.Center or ChartAlign.End.ChartAlignChartAlign.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.SankeyAlignSankeyAlign.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.SankeyOrderSankeyOrder.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.SankeyLinkColorSankeyLinkColor.Source
LabelsWrites each node's name beside its bar, inside the diagram.booltrue
ValuesWrites each node's value after its name, such as "Housing $1,700".boolfalse
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).booltrue
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.ChartDataTableChartDataTable.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

See 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.

Connection lost

Rejoining the server…