Getting started with ASP.NET Core Sankey Diagram Control
23 Jul 20267 minutes to read
This section briefly explains how to include the ASP.NET Core Sankey Diagram control in your ASP.NET Core application using Visual Studio.
Ready to streamline your ASP.NET Core development? Discover the full potential of ASP.NET Core controls with 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, CodeStudio and more. Explore AI Coding Assistant
Create an ASP.NET Core Web App with Razor Pages
Create an ASP.NET Core Web App using Visual Studio via Microsoft Templates or the Syncfusion® ASP.NET Core Extension. For detailed instructions, refer to the ASP.NET Core Web App Getting Started documentation.
Install the required ASP.NET Core package
To add ASP.NET Core Sankey Diagram control in the app, open the NuGet package manager in Visual Studio (Tools → NuGet Package Manager → Manage NuGet Packages for Solution), search for and install the Syncfusion.AspNetCore.Sankey package. All Syncfusion ASP.NET Core packages are available in nuget.org. See the NuGet packages topic for details.
Alternatively, you can install the same package using the Package Manager Console with the following command.
Install-Package Syncfusion.AspNetCore.Sankey -Version 34.1.29Add the ASP.NET Core Tag Helpers
After the package is installed, open the ~/Pages/_ViewImports.cshtml file and import the Syncfusion.AspNetCore.Base and Syncfusion.AspNetCore.Sankey Tag Helpers.
@addTagHelper *, Syncfusion.AspNetCore.Base
@addTagHelper *, Syncfusion.AspNetCore.SankeyAdd script resources
Include the script reference inside the <head> of ~/Pages/Shared/_Layout.cshtml.
<head>
...
<!-- ASP.NET Core controls scripts -->
<script src="_content/Syncfusion.AspNetCore.Sankey/scripts/sf-sankey.min.js"></script>
</head>Register the script manager
Open the ~/Pages/Shared/_Layout.cshtml file and register the script manager <ejs-scripts> at the end of the <body> element as follows.
<body>
...
<!-- ASP.NET Core Script Manager -->
<ejs-scripts></ejs-scripts>
</body>Add ASP.NET Core Sankey Diagram control
Add the ASP.NET Core Sankey Diagram control in the ~/Pages/Index.cshtml file.
<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 Diagram
Now you can add data to the Sankey Diagram control 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();
}Run the application
Press Ctrl+F5 (Windows) or ⌘+F5 (macOS) to launch the application. The ASP.NET Core Sankey Diagram control will render in your default web browser.