How can I help you?
Getting started with ASP.NET Core Sankey Chart Control
23 Mar 20268 minutes to read
This section briefly explains about how to include ASP.NET Core Sankey Chart control in your ASP.NET Core application using Visual Studio.
Ready to streamline your Syncfusion® ASP.NET Core development? Discover the full potential of Syncfusion® ASP.NET Core controls with Syncfusion® AI Coding Assistant. Effortlessly integrate, configure, and enhance your projects with intelligent, context-aware code suggestions, streamlined setups, and real-time insights—all seamlessly integrated into your preferred AI-powered IDEs like Visual Studio, Visual Studio Code, Cursor, Syncfusion® CodeStudio and more. Explore Syncfusion® AI Coding Assistant
Prerequisites
System requirements for ASP.NET Core controls
Create ASP.NET Core web application with Razor pages
Install ASP.NET Core package in the application
To add ASP.NET Core controls in the application, open the NuGet package manager in Visual Studio (Tools → NuGet Package Manager → Manage NuGet Packages for Solution), search for Syncfusion.EJ2.AspNet.Core and then install it. Alternatively, you can utilize the following package manager command to achieve the same.
Install-Package Syncfusion.EJ2.AspNet.Core -Version 33.1.44NOTE
Syncfusion® ASP.NET Core controls are available in nuget.org. Refer to NuGet packages topic to learn more about installing NuGet packages in various OS environments. The Syncfusion.EJ2.AspNet.Core NuGet package has dependencies, Newtonsoft.Json for JSON serialization and Syncfusion.Licensing for validating Syncfusion® license key.
Add Syncfusion® ASP.NET Core Tag Helper
Open ~/Pages/_ViewImports.cshtml file and import the Syncfusion.EJ2 TagHelper.
@addTagHelper *, Syncfusion.EJ2Add script resources
Here, script is referred using CDN inside the <head> of ~/Pages/Shared/_Layout.cshtml file as follows,
<head>
...
<!-- Syncfusion ASP.NET Core controls scripts -->
<script src="https://cdn.syncfusion.com/ej2/33.1.44/dist/ej2.min.js"></script>
</head>NOTE
Checkout the Adding Script Reference topic to learn different approaches for adding script references in your ASP.NET Core application.
Register Syncfusion® Script Manager
Also, register the script manager <ejs-script> at the end of <body> in the ASP.NET Core application as follows.
<body>
...
<!-- Syncfusion ASP.NET Core Script Manager -->
<ejs-scripts></ejs-scripts>
</body>Add ASP.NET Core Sankey Chart control
Now, add the Syncfusion® ASP.NET Core Sankey Chart tag helper in ~/Pages/Index.cshtml page.
<ejs-sankey id="sankey-container" width="90%" height="420px" title="Sankey Chart">
<e-sankey-nodes>
@foreach (var node in ViewBag.SankeyNodes)
{
<e-sankey-node id="@node.Id"></e-sankey-node>
}
</e-sankey-nodes>
<e-sankey-links>
@foreach (var link in ViewBag.SankeyLinks)
{
<e-sankey-link sourceId="@link.SourceId" targetId="@link.TargetId" value="@link.Value"></e-sankey-link>
}
</e-sankey-links>
<e-sankey-tooltipsettings enable="true"></e-sankey-tooltipsettings>
<e-sankey-legendsettings visible="true"></e-sankey-legendsettings>
</ejs-sankey>public ActionResult Index()
{
List<SankeyNode> nodes = new List<SankeyNode>
{
new SankeyNode { Id = "A" },
new SankeyNode { Id = "B" },
new SankeyNode { Id = "C" }
};
List<SankeyLink> links = new List<SankeyLink>
{
new SankeyLink { SourceId = "A", TargetId = "B", Value = 100 },
new SankeyLink { SourceId = "B", TargetId = "C", Value = 80 }
};
ViewBag.SankeyNodes = nodes;
ViewBag.SankeyLinks = links;
return View();
}Add data to Sankey Chart
Now you can add data to the Sankey Chart component by defining nodes and links. Nodes represent the categories, and links represent the flow between them.
<ejs-sankey id="sankey-container" width="90%" height="420px" title="Energy Flow Diagram">
<e-sankey-nodes>
@foreach (var node in ViewBag.SankeyNodes)
{
<e-sankey-node id="@node.Id" label="@node.Label"></e-sankey-node>
}
</e-sankey-nodes>
<e-sankey-links>
@foreach (var link in ViewBag.SankeyLinks)
{
<e-sankey-link sourceId="@link.SourceId" targetId="@link.TargetId" value="@link.Value"></e-sankey-link>
}
</e-sankey-links>
<e-sankey-tooltipsettings enable="true"></e-sankey-tooltipsettings>
<e-sankey-legendsettings visible="true"></e-sankey-legendsettings>
</ejs-sankey>public ActionResult Index()
{
List<SankeyNode> nodes = new List<SankeyNode>
{
new SankeyNode { Id = "Energy Input", Label = new SankeyChartDataLabel { Text = "Energy Input" } },
new SankeyNode { Id = "Generation", Label = new SankeyChartDataLabel { Text = "Generation" } },
new SankeyNode { Id = "Distribution", Label = new SankeyChartDataLabel { Text = "Distribution" } },
new SankeyNode { Id = "Consumption", Label = new SankeyChartDataLabel { Text = "Consumption" } }
};
List<SankeyLink> links = new List<SankeyLink>
{
new SankeyLink { SourceId = "Energy Input", TargetId = "Generation", Value = 500 },
new SankeyLink { SourceId = "Generation", TargetId = "Distribution", Value = 450 },
new SankeyLink { SourceId = "Distribution", TargetId = "Consumption", Value = 400 }
};
ViewBag.SankeyNodes = nodes;
ViewBag.SankeyLinks = links;
return View();
}Press Ctrl+F5 (Windows) or ⌘+F5 (macOS) to run the app. Then, the Syncfusion® ASP.NET Core Chart control will be rendered in the default web browser.