DwsSankeyGraph
Shows how a quantity flows between stages. Nodes are placed in columns and links are drawn as bands as thick as their value, all computed from the data. The graph lays itself out at the width it gets, so it fills any container and keeps its labels readable on a phone.
API ReferenceBasic
Only nodes and links are needed. Sources start on the left, sinks end on the right, and every node without a color of its own takes the next theme color.
Show Code
SankeyGraph.razor
<DwsSankeyGraph Name='SankeyGraphDemo_Basic' GraphData='@_budget' Height='360' />SankeyGraph.razor.cs
private readonly DwsSankeyGraphData _budget = new()
{
Nodes =
[
new DwsSankeyGraphNode { Id = "salary", Label = "Salary" },
new DwsSankeyGraphNode { Id = "sidejob", Label = "Side job" },
new DwsSankeyGraphNode { Id = "budget", Label = "Budget", Description = "Everything that comes in this month." },
new DwsSankeyGraphNode { Id = "rent", Label = "Rent" },
new DwsSankeyGraphNode { Id = "groceries", Label = "Groceries" },
new DwsSankeyGraphNode { Id = "leisure", Label = "Leisure" },
new DwsSankeyGraphNode { Id = "savings", Label = "Savings" },
new DwsSankeyGraphNode { Id = "etf", Label = "ETF" },
new DwsSankeyGraphNode { Id = "emergency", Label = "Emergency fund" },
],
Links =
[
new DwsSankeyGraphLink { Source = "salary", Target = "budget", Value = 3200 },
new DwsSankeyGraphLink { Source = "sidejob", Target = "budget", Value = 600 },
new DwsSankeyGraphLink { Source = "budget", Target = "rent", Value = 1300 },
new DwsSankeyGraphLink { Source = "budget", Target = "groceries", Value = 700 },
new DwsSankeyGraphLink { Source = "budget", Target = "leisure", Value = 500 },
new DwsSankeyGraphLink { Source = "budget", Target = "savings", Value = 1300 },
new DwsSankeyGraphLink { Source = "savings", Target = "etf", Value = 900 },
new DwsSankeyGraphLink { Source = "savings", Target = "emergency", Value = 400 },
],
};Theme colors
Node and link colors are theme colors (DwsColor), so the graph follows the active theme. LinkColorMode decides whether a link takes the color of its source, its target or one neutral color.
Show Code
SankeyGraph.razor
@foreach (DwsSankeyLinkColorMode mode in Enum.GetValues<DwsSankeyLinkColorMode>())
{
<DwsButton Name='@($"SankeyGraphDemo_LinkColorMode_{mode}")'
Appearance='@(_linkColorMode == mode ? DwsAppearance.Filled : DwsAppearance.Outline)'
ButtonSize='DwsSize.Small'
OnClick='() => _linkColorMode = mode'>@mode</DwsButton>
}
<DwsSankeyGraph Name='SankeyGraphDemo_Colors' GraphData='@_energy' LinkColorMode='@_linkColorMode' Height='320' />SankeyGraph.razor.cs
private DwsSankeyLinkColorMode _linkColorMode = DwsSankeyLinkColorMode.Source;
private readonly DwsSankeyGraphData _energy = new()
{
Nodes =
[
new DwsSankeyGraphNode { Id = "solar", Label = "Solar", Color = DwsColor.Warning },
new DwsSankeyGraphNode { Id = "grid", Label = "Grid", Color = DwsColor.Secondary },
new DwsSankeyGraphNode { Id = "battery", Label = "Battery", Color = DwsColor.Success },
new DwsSankeyGraphNode { Id = "house", Label = "House", Color = DwsColor.Primary },
new DwsSankeyGraphNode { Id = "car", Label = "Car", Color = DwsColor.Info },
new DwsSankeyGraphNode { Id = "export", Label = "Export", Color = DwsColor.Error },
],
Links =
[
new DwsSankeyGraphLink { Source = "solar", Target = "battery", Value = 8 },
new DwsSankeyGraphLink { Source = "solar", Target = "house", Value = 10 },
new DwsSankeyGraphLink { Source = "solar", Target = "export", Value = 4 },
new DwsSankeyGraphLink { Source = "grid", Target = "house", Value = 6 },
new DwsSankeyGraphLink { Source = "grid", Target = "car", Value = 5 },
new DwsSankeyGraphLink { Source = "battery", Target = "house", Value = 5 },
new DwsSankeyGraphLink { Source = "battery", Target = "car", Value = 3 },
],
};Values in labels
ShowValues adds the flow to each label, formatted with ValueFormat in the current culture; here as currency without decimals (C0).
Show Code
SankeyGraph.razor
<DwsSankeyGraph Name='SankeyGraphDemo_ValuesGraph' GraphData='@_budget' Height='360' ShowValues='true' ValueFormat='C0' />SankeyGraph.razor.cs
private readonly DwsSankeyGraphData _budget = new()
{
Nodes =
[
new DwsSankeyGraphNode { Id = "salary", Label = "Salary" },
new DwsSankeyGraphNode { Id = "sidejob", Label = "Side job" },
new DwsSankeyGraphNode { Id = "budget", Label = "Budget", Description = "Everything that comes in this month." },
new DwsSankeyGraphNode { Id = "rent", Label = "Rent" },
new DwsSankeyGraphNode { Id = "groceries", Label = "Groceries" },
new DwsSankeyGraphNode { Id = "leisure", Label = "Leisure" },
new DwsSankeyGraphNode { Id = "savings", Label = "Savings" },
new DwsSankeyGraphNode { Id = "etf", Label = "ETF" },
new DwsSankeyGraphNode { Id = "emergency", Label = "Emergency fund" },
],
Links =
[
new DwsSankeyGraphLink { Source = "salary", Target = "budget", Value = 3200 },
new DwsSankeyGraphLink { Source = "sidejob", Target = "budget", Value = 600 },
new DwsSankeyGraphLink { Source = "budget", Target = "rent", Value = 1300 },
new DwsSankeyGraphLink { Source = "budget", Target = "groceries", Value = 700 },
new DwsSankeyGraphLink { Source = "budget", Target = "leisure", Value = 500 },
new DwsSankeyGraphLink { Source = "budget", Target = "savings", Value = 1300 },
new DwsSankeyGraphLink { Source = "savings", Target = "etf", Value = 900 },
new DwsSankeyGraphLink { Source = "savings", Target = "emergency", Value = 400 },
],
};Loading, caption and empty
IsLoading shows a spinner in place of the drawing while the data is on its way. Caption puts a sentence under the chart - what it shows, the source - and screen readers describe the drawing with it. EmptyContent replaces the empty text when there is nothing to draw; without it NoDataText or the localized default is shown, as in the last example.
Household budget for one month, in euros.
Show Code
SankeyGraph.razor
<DwsSwitch Name='SankeyGraphDemo_States_Loading' @bind-Value='_statesLoading' Label='IsLoading' Class='mb-2' />
<DwsSankeyGraph Name='SankeyGraphDemo_States_Chart' GraphData='@_budget' Height='280' IsLoading='@_statesLoading' Caption='Household budget for one month, in euros.' />
<!-- Nothing to draw: your own content -->
<DwsSankeyGraph Name='SankeyGraphDemo_States_EmptyContent' GraphData='null' Height='160' Class='mt-3'>
<EmptyContent>
<span>No bookings this month yet.</span>
</EmptyContent>
</DwsSankeyGraph>
<!-- Nothing to draw, no EmptyContent: NoDataText or the localized default -->
<DwsSankeyGraph Name='SankeyGraphDemo_Empty' GraphData='null' Height='120' />SankeyGraph.razor.cs
private readonly DwsSankeyGraphData _budget = new()
{
Nodes =
[
new DwsSankeyGraphNode { Id = "salary", Label = "Salary" },
new DwsSankeyGraphNode { Id = "sidejob", Label = "Side job" },
new DwsSankeyGraphNode { Id = "budget", Label = "Budget", Description = "Everything that comes in this month." },
new DwsSankeyGraphNode { Id = "rent", Label = "Rent" },
new DwsSankeyGraphNode { Id = "groceries", Label = "Groceries" },
new DwsSankeyGraphNode { Id = "leisure", Label = "Leisure" },
new DwsSankeyGraphNode { Id = "savings", Label = "Savings" },
new DwsSankeyGraphNode { Id = "etf", Label = "ETF" },
new DwsSankeyGraphNode { Id = "emergency", Label = "Emergency fund" },
],
Links =
[
new DwsSankeyGraphLink { Source = "salary", Target = "budget", Value = 3200 },
new DwsSankeyGraphLink { Source = "sidejob", Target = "budget", Value = 600 },
new DwsSankeyGraphLink { Source = "budget", Target = "rent", Value = 1300 },
new DwsSankeyGraphLink { Source = "budget", Target = "groceries", Value = 700 },
new DwsSankeyGraphLink { Source = "budget", Target = "leisure", Value = 500 },
new DwsSankeyGraphLink { Source = "budget", Target = "savings", Value = 1300 },
new DwsSankeyGraphLink { Source = "savings", Target = "etf", Value = 900 },
new DwsSankeyGraphLink { Source = "savings", Target = "emergency", Value = 400 },
],
};
private bool _statesLoading;Minimum width
MinWidth is the last resort for a graph with too many columns to read at phone width. This one scrolls sideways on purpose: the graph keeps 560px, the dashed 320px box stands for a phone, and only the graph scrolls inside it - the page itself stays put. The edge behind which more of the graph waits fades out until it is scrolled into view (ShowScrollHint='false' switches that off). Prefer AdaptLabelsToWidth and fewer columns where you can.
Show Code
SankeyGraph.razor
<div class='sankey-demo-narrow'>
<DwsSankeyGraph Name='SankeyGraphDemo_MinWidth' GraphData='@_energy' Height='280' MinWidth='560' />
</div>
<style>
.sankey-demo-narrow {
width: 320px;
max-width: 100%;
padding: 0.5rem;
border: 1px dashed var(--secondary);
}
</style>SankeyGraph.razor.cs
private DwsSankeyLinkColorMode _linkColorMode = DwsSankeyLinkColorMode.Source;
private readonly DwsSankeyGraphData _energy = new()
{
Nodes =
[
new DwsSankeyGraphNode { Id = "solar", Label = "Solar", Color = DwsColor.Warning },
new DwsSankeyGraphNode { Id = "grid", Label = "Grid", Color = DwsColor.Secondary },
new DwsSankeyGraphNode { Id = "battery", Label = "Battery", Color = DwsColor.Success },
new DwsSankeyGraphNode { Id = "house", Label = "House", Color = DwsColor.Primary },
new DwsSankeyGraphNode { Id = "car", Label = "Car", Color = DwsColor.Info },
new DwsSankeyGraphNode { Id = "export", Label = "Export", Color = DwsColor.Error },
],
Links =
[
new DwsSankeyGraphLink { Source = "solar", Target = "battery", Value = 8 },
new DwsSankeyGraphLink { Source = "solar", Target = "house", Value = 10 },
new DwsSankeyGraphLink { Source = "solar", Target = "export", Value = 4 },
new DwsSankeyGraphLink { Source = "grid", Target = "house", Value = 6 },
new DwsSankeyGraphLink { Source = "grid", Target = "car", Value = 5 },
new DwsSankeyGraphLink { Source = "battery", Target = "house", Value = 5 },
new DwsSankeyGraphLink { Source = "battery", Target = "car", Value = 3 },
],
};Interface-Description
| Name | Typ | Parameters | Description |
|---|---|---|---|
| SetNodeOrderAsync(IEnumerable<string> nodeIds) | Task | Puts nodes into this order within their columns (ids top to bottom; nodes that are not named follow in the order of the data). For restoring a stored order; raises no event. | |
| ResetNodeOrderAsync | Task | Forgets every reorder: the nodes of each column stand in the order of the data again. | |
| GetColumnOrder(int column) | IReadOnlyList<string> | The ids of the nodes of a column, top to bottom, as they are drawn. |
| Name | Typ | Default | Description |
|---|---|---|---|
| GraphData | DwsSankeyGraphData? | null | The nodes and links to draw. Node order is the top-to-bottom order within a column. Links to unknown nodes, links back to their own node, links with a value that is not a positive number and links that would close a cycle are skipped and logged as a warning. |
| Title | string? | null | Caption above the graph, also its accessible name. |
| NoDataText | string? | null | Text shown when there are no nodes. Null uses the localized "No data to display". |
| EmptyContent | RenderFragment? | null | Shown instead of the graph when there is nothing to draw; null shows the localized empty text. |
| IsLoading | bool | false | The data is still loading: a spinner instead of the graph. |
| Caption | string? | null | A sentence under the graph (what it shows, the source); the graph is described by it (aria-describedby). |
| Width | int? | null | Width in px. The graph never gets wider than its container and lays itself out again at the width it has. Null fills the container. |
| Height | int | 400 | Height of the drawing area in px. |
| MinWidth | int? | null | Narrowest width in px the graph is laid out at; a narrower container scrolls it sideways instead of squeezing its columns. |
| ShowScrollHint | bool | true | With MinWidth: fades the edge of the graph behind which more of it can be scrolled into view. Needs interactivity; nothing is faded while the whole graph is in view. |
| AdaptLabelsToWidth | bool | true | Fits each node's label into the room the graph leaves it at the width it has: wrapped onto as many lines as its node is high (at most three), and what still does not fit ends in an ellipsis; a label with no room at all is left out. The full text stays in the node's accessible name and tooltip. The gap before the last column is shared by the labels on both its sides. Off draws every label in full on one line. |
| NodeWidth | int | 16 | Width of a node bar in px. |
| NodePadding | int | 12 | Vertical gap between the nodes of a column in px. Shrinks in a crowded column so its nodes still fit. |
| LinkColorMode | DwsSankeyLinkColorMode | DwsSankeyLinkColorMode.Source | Color of a link without a color of its own: its source's, its target's, or one neutral color (Neutral). |
| ShowLabels | bool | true | Shows each node's label next to it: on the right, in the last column on the left. |
| ShowValues | bool | false | Adds the flow through the node to its label. |
| ValueFormat | string | "#,0.##" | .NET number format for values in labels, legend and tooltip, in the current UI culture. |
| WithLegend | bool | false | Shows a wrapping legend of the nodes with color and flow below the graph. Its entries highlight and select their node. |
| HighlightOnHover | bool | true | Dims everything not connected to the hovered, focused or selected node or link. |
| AllowNodeReorder | bool | false | Lets the user move a node up or down within its column: by dragging it, or with Alt and the up or down arrow key on the focused node. The graph keeps the new order (the data is not written to). Needs interactivity for the pointer. |
| ShowTooltip | bool | true | Shows the detail of the hovered, focused or selected node or link. On touch screens a tap selects a node and shows its detail. |
| NodeDetailTemplate | RenderFragment<DwsSankeyGraphNodeDetail>? | null | Tooltip content for a node. Null shows label, description, inflow and outflow. |
| LinkDetailTemplate | RenderFragment<DwsSankeyGraphLinkDetail>? | null | Tooltip content for a link. Null shows source → target, label and value with its share of the source. |
| SelectedNodeId | string? | null | Id of the selected node. Click, Enter or Space selects a node, a second one (or Escape) clears it. Two-way bindable. |
| Name | Typ | Description |
|---|---|---|
| SelectedNodeIdChanged | EventCallback<string?> | Raised when the user selects a node or clears the selection. |
| OnNodeClick | EventCallback<DwsSankeyGraphNodeDetail> | Raised when a node or its legend entry is clicked or activated with Enter/Space. Not raised while disabled or in permission select mode (a click then selects the graph). |
| OnLinkClick | EventCallback<DwsSankeyGraphLinkDetail> | Raised when a link is clicked or activated with Enter/Space (links are focusable too). Not raised while disabled or in permission select mode. |
| OnNodeHover | EventCallback<DwsSankeyGraphNodeDetail?> | Raised when the pointer or focus enters a node, and with null when it leaves. |
| OnLinkHover | EventCallback<DwsSankeyGraphLinkDetail?> | Raised when the pointer or focus enters a link, and with null when it leaves. |
| OnNodeReordered | EventCallback<DwsSankeyGraphNodeReorderedEventArgs> | Raised when the user moved a node to another place in its column: Node, Column, OldIndex, NewIndex, Order (the ids of the column top to bottom) and ByKeyboard. |
| Name | Typ | Default | Description |
|---|---|---|---|
| Element | ElementReference | The associated web component. May be null if accessed before the component is rendered. | |
| ComponentGuid | Guid | Unique identifier for the component. | |
| TypeString | string | The name of the component type, obtained from reflection. | |
| Authorized_RegisterEnabled | bool | false | Indicates whether this component is enabled through a permission registry. |
| Authorized_RegisterSelected | bool | false | Indicates whether this component is selected in permission selection mode. |
| GetInitializedState | bool | false | Returns whether the component is initialized. |
| GetRenderModeState | DwsRenderMode | Returns the current render mode. | |
| GetComponentState | DwsComponentStateType | Returns the current component state. | |
| GetIsInteractiveState | bool | false | Returns whether the component is interactive. |
| GetIsPrerenderingState | bool | false | Returns whether the component is prerendering. |
| GetComponentLoadingState | bool | false | Returns whether the component is loading. |
| IsFormBusy | bool | false | Whether the DwsForm (or DwsFormBusyRegion) around the component is locked because its submit handler is running. The state itself is the cascaded FormBusyState (IDwsFormBusyState). |
| Name | Typ | Parameters | Description |
|---|---|---|---|
| DebugInfo | void | Logs debug information about the component. | |
| UpdateState | void | Updates the component's state and triggers StateHasChanged. | |
| UpdateStateAsync | Task | Asynchronously updates the component's state and triggers StateHasChanged. | |
| Dispose | void | Disposes the component and releases resources. | |
| FocusAsync | ValueTask | bool containedInScrollableList | Sets focus to the component's element. |
| Name | Typ | Default | Description |
|---|---|---|---|
| Name | string | Required unique identifier for the component within its container. | |
| Visible | bool | true | Determines if the component is visible in the UI. |
| Disabled | bool | false | Disables the form control, ensuring it doesn't participate in form submission. |
| ComponentNameSpace | string | The namespace for permission-based access control. | |
| PermissionKey | string? | null | A stable key that takes the place of Name in the generated permission namespace (Page.PermissionKey): the stored permission survives a rename, and components that share a key share one permission entry. Null: keyed by Name. Read once, when the component registers; an explicit ComponentNameSpace wins. |
| Class | string | Optional CSS class names. | |
| Style | string | Optional in-line styles. | |
| Tag | object | An optional user-defined object to store any additional data with the component. | |
| BackReference | DwsReference | A reference to the enclosing component. | |
| ID | string | The HTML ID attribute for the component. | |
| AdditionalAttributes | Dictionary<string, object> | Additional HTML attributes for the component's root element. | |
| IgnorePermissionChecks | bool | false | Bypasses all permission checks for this component. |
| IgnorePermissionSelection | bool | false | Ignore permission selection mode for this component. |
| IgnoreFormBusy | bool | false | Takes the component out of the submit lock of the DwsForm (or DwsFormBusyRegion) around it: IsFormBusy stays false for it. |
| Name | Typ | Description |
|---|---|---|
| OnInitializedCallbackStarted | EventCallback | Callback when OnInitialized starts. |
| OnInitializedCallback | EventCallback | Callback during OnInitialized. |
| OnInitializedCallbackCompleted | EventCallback | Callback when OnInitialized completes. |
| OnInitializedAsyncCallbackStarted | EventCallback | Callback when OnInitializedAsync starts. |
| OnInitializedAsyncCallback | EventCallback | Callback during OnInitializedAsync. |
| OnInitializedAsyncCallbackCompleted | EventCallback | Callback when OnInitializedAsync completes. |
| OnIsComponentLoadingChanged | EventCallback<bool> | Callback when IsComponentLoading changes. |
| OnCurrentRenderModeChanged | EventCallback<DwsRenderMode> | Callback when CurrentRenderMode changes. |
| OnComponentStateChanged | EventCallback<DwsComponentStateType> | Callback when ComponentState changes. |
