Blazor-ApexSankey
1.3.0
dotnet add package Blazor-ApexSankey --version 1.3.0
NuGet\Install-Package Blazor-ApexSankey -Version 1.3.0
<PackageReference Include="Blazor-ApexSankey" Version="1.3.0" />
<PackageVersion Include="Blazor-ApexSankey" Version="1.3.0" />
<PackageReference Include="Blazor-ApexSankey" />
paket add Blazor-ApexSankey --version 1.3.0
#r "nuget: Blazor-ApexSankey, 1.3.0"
#:package Blazor-ApexSankey@1.3.0
#addin nuget:?package=Blazor-ApexSankey&version=1.3.0
#tool nuget:?package=Blazor-ApexSankey&version=1.3.0
Blazor-ApexSankey
A Blazor component library for creating interactive Sankey diagrams using ApexSankey. Built for Blazor WebAssembly with full support for two-way data binding, customizable styling, and event handling.
Features
- 🔗 Two-Way Binding - Automatic re-rendering when data changes
- 🎨 Fully Customizable - Control nodes, edges, fonts, colors, and tooltips
- ⚡ Event Handling - Handle node clicks and render callbacks
- 📱 WebAssembly - Built specifically for Blazor WebAssembly
- 🛠️ TypeScript Definitions - Full IntelliSense support
- 📦 Easy Integration - Simple NuGet package installation
Installation
dotnet add package Blazor-ApexSankey
Quick Start
1. Add the script reference
The core library is self-contained (no external dependencies), so the standard Blazor script is all you need in your index.html:
<script src="_framework/blazor.webassembly.js"></script>
2. Add the using statement
In your _Imports.razor:
@using Blazor_ApexSankey.Components
@using Blazor_ApexSankey.Models
@using Blazor_ApexSankey.Events
@using Blazor_ApexSankey.Services
3. Use the component
@page "/my-sankey"
<ApexSankey Data="@sankeyData"
Options="@options"
OnNodeClick="@HandleNodeClick" />
@code {
private SankeyData sankeyData = new()
{
Nodes = new List<SankeyNode>
{
new() { Id = "A", Title = "Source A" },
new() { Id = "B", Title = "Source B" },
new() { Id = "C", Title = "Target C" }
},
Edges = new List<SankeyEdge>
{
new() { Source = "A", Target = "C", Value = 10 },
new() { Source = "B", Target = "C", Value = 20 }
}
};
private SankeyOptions options = new()
{
Width = "800",
Height = "600",
NodeWidth = 20,
FontFamily = "Arial, sans-serif"
};
private void HandleNodeClick(NodeClickEventArgs args)
{
Console.WriteLine($"Clicked node: {args.Node.Title}");
}
}
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
Width |
string |
"100%" |
Container width |
Height |
string |
"auto" |
Container height |
CanvasStyle |
string |
null |
CSS styles for canvas |
Spacing |
int |
20 |
Horizontal spacing between node columns |
NodeWidth |
int |
20 |
Width of nodes |
NodeBorderWidth |
int |
1 |
Node border width |
NodeBorderColor |
string |
null |
Node border color |
EdgeOpacity |
double |
0.4 |
Edge opacity (0-1) |
EdgeGradientFill |
bool |
true |
Enable gradient fill |
EnableTooltip |
bool |
false |
Show tooltips |
EnableToolbar |
bool |
false |
Show toolbar |
TooltipTemplate |
string |
null |
Custom tooltip JS function |
TooltipBorderColor |
string |
"#BCBCBC" |
Tooltip border color |
TooltipBGColor |
string |
"#FFFFFF" |
Tooltip background |
FontSize |
string |
"14px" |
Node label font size |
FontFamily |
string |
null |
Font family |
FontWeight |
string |
"400" |
Font weight |
FontColor |
string |
"#000000" |
Label color |
Data Models
SankeyNode
public class SankeyNode
{
public string Id { get; set; } // required
public string Title { get; set; } // required
public string? Color { get; set; } // optional
}
SankeyEdge
public class SankeyEdge
{
public string Source { get; set; } // required
public string Target { get; set; } // required
public double Value { get; set; } // required
public string? Type { get; set; } // optional
public string? Color { get; set; } // optional
}
Custom Ordering
You can specify custom node ordering:
var data = new SankeyData
{
Nodes = nodes,
Edges = edges,
Options = new SankeyDataOptions
{
Order = new List<List<List<string>>>
{
new() { new() { "A", "B" } },
new() { new() { "C" } }
}
}
};
Events
| Event | Type | Description |
|---|---|---|
OnNodeClick |
EventCallback<NodeClickEventArgs> |
Fired when a node is clicked |
OnRender |
EventCallback |
Fired after chart renders |
Ignite UI theming
From Blazor-ApexSankey 1.3.0, which bundles apexsankey 1.14.0, diagrams can follow the Ignite UI theme on the page: the node palette, label text, the focus ring, the font, the tooltip, light or dark. It is an add-on, it is free, and it needs no license key. Turn it on once in Program.cs:
ApexSankeyIgniteUI.Enable();
The component then loads _content/Blazor-ApexSankey/apexsankey.ignite-ui.es.min.js before the first diagram renders. To load it yourself instead, add the script-tag build to index.html (or App.razor), before or after the Blazor script:
<script src="_content/Blazor-ApexSankey/apexsankey.ignite-ui.min.js"></script>
The Ignite UI tokens (--ig-*) are the lowest-ranked layer above the built-in defaults. Anything above them wins:
| Rank | Source |
|---|---|
| 1 | An option you pass in SankeyOptions |
| 2 | An --apex-sankey-* CSS variable |
| 3 | An --apx-* family token |
| 4 | A named or registered Theme |
| 5 | The Ignite UI theme (--ig-*), with the add-on loaded |
| 6 | The built-in defaults |
To turn it off for one diagram, set DesignSystem = false; the --apx-* tokens still apply. Tokens = false stops every token read (--apx-* and --ig-*). Without the add-on the --ig-* tokens are ignored, with no error.
The diagram reads its theme on every render. After a change that does not render, such as swapping the Ignite UI stylesheet for its dark variant, call RefreshTokensAsync() on the component (through @ref); node positions are kept.
The font comes from --ig-font-family, which is usually a web font, and the Ignite UI theme sheets do not load it. Load the font on the page; if it finishes loading after the first render, call RefreshTokensAsync() so the labels are measured with it.
Licensing
To use with a commercial license:
// set before creating any chart instances
await ApexSankeyInterop.SetLicenseAsync(jsRuntime, "your-license-key");
Browser Support
Blazor-ApexSankey supports all modern browsers that support WebAssembly:
- Chrome 57+
- Firefox 52+
- Safari 11+
- Edge 16+
License
See LICENSE for details.
Links
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- Microsoft.AspNetCore.Components.Web (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
1.3.0 Upgrades the bundled apexsankey core to 1.14.0 and adds opt-in Ignite UI theming: call ApexSankeyIgniteUI.Enable() and diagrams take their node colours, text, tooltip and font from the Ignite UI theme on the page. The add-on is free and needs no license key. SankeyOptions gains Tokens and DesignSystem to turn the shared tokens or the page theme off per diagram, and RefreshTokensAsync() repaints after a stylesheet or theme switch without moving nodes. Behaviour change from the core: an option you pass in SankeyOptions now beats an --apex-sankey-* CSS variable for the same setting; before, the variable won.
1.2.1 Corrects the package licence metadata. Releases up to and including 1.2.0 declared the SPDX expression MIT, which was wrong: this package embeds the ApexSankey engine, and ApexSankey is a commercial product included in the Pro plan and above with no free tier. The LICENSE file in the repository always stated those terms, so the package contradicted its own licence document. 1.2.1 declares the LICENSE file itself and ships it inside the package. No code changes.
1.2.0 Ports the apexsankey 1.11.0 option surface into the C# model: type (chord), arcCornerRadius, theme (named or inline SankeyTheme) and nodePalette, orientation, whitespace, axisTitles, viewPortWidth/Height, draggableNodes, particleFlow, nodeTooltipTemplate, tooltipTheme, tooltipFontColor, and a11y. Adds a Plugins option to install the built-in path tracing, time playback, and drill-down plugins. Non-breaking over 1.1.0.