Example of 100% StackingLine in ASP.NET MVC Charts Control
This 100% Stacked Line Chart example visualizes the blood type distribution across different countries.
${x} : ${y}% (${percentage}%)
@Html.UiChart(new UiChartOptions
{
Id = "stackLine100Chart",
Title = "Blood Type Distribution by Country",
SubTitle = "Source: wikipedia.org",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, ShowNearestTooltip = true, EnableHighlight = true, Template = "#tipStackingLine100" },
Legend = new UiChartLegend { EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category, ShowGridLines = false },
PrimaryYAxis = new UiChartAxis { Interval = 20, Title = "Population Share (%)" },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.StackingLine100, Width = 2, XName = "X", YName = "Y", Name = "Canada", Opacity = 1, Marker = new UiChartMarker { Visible = true, Width = 7, Height = 7, Shape = UiChartMarkerShape.Circle, IsFilled = true } },
new UiChartSeries { Type = UiChartSeriesType.StackingLine100, Width = 2, XName = "X", YName = "Y1", Name = "Algeria", Opacity = 1, Marker = new UiChartMarker { Visible = true, Width = 7, Height = 7, Shape = UiChartMarkerShape.Diamond, IsFilled = true } },
new UiChartSeries { Type = UiChartSeriesType.StackingLine100, Width = 2, XName = "X", YName = "Y2", Name = "Ireland", Opacity = 1, Marker = new UiChartMarker { Visible = true, Width = 5, Height = 5, Shape = UiChartMarkerShape.Rectangle, IsFilled = true } },
new UiChartSeries { Type = UiChartSeriesType.StackingLine100, Width = 2, XName = "X", YName = "Y3", Name = "Armenia", Opacity = 1, Marker = new UiChartMarker { Visible = true, Width = 6, Height = 6, Shape = UiChartMarkerShape.Triangle, IsFilled = true } }
}
})
<template id="tipStackingLine100">${x} : <b>${y}% (${percentage}%)</b></template>
@Html.UiChart(new UiChartOptions
{
Id = "stackLine100Chart",
Title = "Blood Type Distribution by Country",
SubTitle = "Source: wikipedia.org",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, ShowNearestTooltip = true, EnableHighlight = true, Template = "#tipStackingLine100" },
Legend = new UiChartLegend { EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category, ShowGridLines = false },
PrimaryYAxis = new UiChartAxis { Interval = 20, Title = "Population Share (%)" },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.StackingLine100, Width = 2, XName = "X", YName = "Y", Name = "Canada", Opacity = 1, Marker = new UiChartMarker { Visible = true, Width = 7, Height = 7, Shape = UiChartMarkerShape.Circle, IsFilled = true } },
new UiChartSeries { Type = UiChartSeriesType.StackingLine100, Width = 2, XName = "X", YName = "Y1", Name = "Algeria", Opacity = 1, Marker = new UiChartMarker { Visible = true, Width = 7, Height = 7, Shape = UiChartMarkerShape.Diamond, IsFilled = true } },
new UiChartSeries { Type = UiChartSeriesType.StackingLine100, Width = 2, XName = "X", YName = "Y2", Name = "Ireland", Opacity = 1, Marker = new UiChartMarker { Visible = true, Width = 5, Height = 5, Shape = UiChartMarkerShape.Rectangle, IsFilled = true } },
new UiChartSeries { Type = UiChartSeriesType.StackingLine100, Width = 2, XName = "X", YName = "Y3", Name = "Armenia", Opacity = 1, Marker = new UiChartMarker { Visible = true, Width = 6, Height = 6, Shape = UiChartMarkerShape.Triangle, IsFilled = true } }
}
})
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class ChartController : Controller
{
// The page is Views/Chart/StackingLine100.cshtml; it draws what ViewData holds.
public ActionResult StackingLine100()
{
List<StackedLineChartData100> ChartPoints = new List<StackedLineChartData100>
{
new StackedLineChartData100 { X= "O+ve", Y= 39.0, Y1= 40.0, Y2= 47.0, Y3= 29.0 },
new StackedLineChartData100 { X= "A+ve", Y= 36.0, Y1= 30.0, Y2= 26.0, Y3= 46.3 },
new StackedLineChartData100 { X= "B+ve", Y= 7.6 , Y1= 15.0, Y2= 9.0 , Y3= 12.0 },
new StackedLineChartData100 { X= "AB+ve", Y= 2.5 , Y1= 4.25, Y2= 2.0 , Y3= 5.6 },
new StackedLineChartData100 { X= "O-ve", Y= 7.0 , Y1= 6.6 , Y2= 8.0 , Y3= 2.0 },
new StackedLineChartData100 { X= "A-ve", Y= 6.0 , Y1= 2.3 , Y2= 5.0 , Y3= 3.7 },
new StackedLineChartData100 { X= "B-ve", Y= 1.4 , Y1= 1.1 , Y2= 2.0 , Y3= 1.0 },
new StackedLineChartData100 { X= "AB-ve", Y= 0.5 , Y1= 0.75, Y2= 1.0 , Y3= 0.4 },
};
ViewData["ChartPoints"] = ChartPoints;
return View();
}
public class StackedLineChartData100
{
public string X { get; set; }
public double Y { get; set; }
public double Y1 { get; set; }
public double Y2 { get; set; }
public double Y3 { get; set; }
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
@* Charts with a DataUrl: @Html.AntiForgeryToken() on the page and [HttpPost, ValidateJsonAntiForgeryToken] on the action. *@
In this example, you can see how to render and configure the 100% stacked line chart. This chart displays multiple series of data as stacked lines, ensuring that the cumulative proportion of each stacked element always totals 100%. Markers are used to represent individual data and its values.
Tooltip is enabled in this example. To see a tooltip in action, hover over or tap on the chart.