Example of StackingStepArea in ASP.NET MVC Charts Control
This sample visualizes the data about electricity production using stacked stepped area chart.
@* The chart's settings are in the view; the data they read (ViewData) is set in the controller action (see the controller tab). *@
@Html.UiChart(new UiChartOptions
{
Id = "stackStepChart",
Title = "Electricity- Production",
Data = (IEnumerable<object>)ViewData["dataSource"],
Legend = new UiChartLegend { EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Double, ShowGridLines = false },
PrimaryYAxis = new UiChartAxis { LabelFormat = "{value}B", Title = "Production (Billion as kWh)" },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.StackingStepArea, Width = 2, XName = "xValue", YName = "yValue", Name = "Renewable", Fill = "#56CCF2", Opacity = 0.5 },
new UiChartSeries { Type = UiChartSeriesType.StackingStepArea, Width = 2, XName = "xValue", YName = "yValue1", Name = "Non-Renewable", Fill = "#2F80ED", Opacity = 0.5 }
}
})
@Html.UiChart(new UiChartOptions
{
Id = "stackStepChart",
Title = "Electricity- Production",
Data = (IEnumerable<object>)ViewData["dataSource"],
Legend = new UiChartLegend { EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Double, ShowGridLines = false },
PrimaryYAxis = new UiChartAxis { LabelFormat = "{value}B", Title = "Production (Billion as kWh)" },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.StackingStepArea, Width = 2, XName = "xValue", YName = "yValue", Name = "Renewable", Fill = "#56CCF2", Opacity = 0.5 },
new UiChartSeries { Type = UiChartSeriesType.StackingStepArea, Width = 2, XName = "xValue", YName = "yValue1", Name = "Non-Renewable", Fill = "#2F80ED", Opacity = 0.5 }
}
})
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/StackingStepArea.cshtml; it draws what ViewData holds.
public ActionResult StackingStepArea()
{
List<StackedStepAreaChartData> chartData = new List<StackedStepAreaChartData>
{
new StackedStepAreaChartData { xValue = 2000, yValue = 416, yValue1 = 180 },
new StackedStepAreaChartData { xValue = 2001, yValue = 490, yValue1 = 240 },
new StackedStepAreaChartData { xValue = 2002, yValue = 470, yValue1 = 370 },
new StackedStepAreaChartData { xValue = 2003, yValue = 500, yValue1 = 200 },
new StackedStepAreaChartData { xValue = 2004, yValue = 449, yValue1 = 229 },
new StackedStepAreaChartData { xValue = 2005, yValue = 470, yValue1 = 210 },
new StackedStepAreaChartData { xValue = 2006, yValue = 437, yValue1 = 337 },
new StackedStepAreaChartData { xValue = 2007, yValue = 458, yValue1 = 258 },
new StackedStepAreaChartData { xValue = 2008, yValue = 500, yValue1 = 300 },
new StackedStepAreaChartData { xValue = 2009, yValue = 473, yValue1 = 173 },
new StackedStepAreaChartData { xValue = 2010, yValue = 520, yValue1 = 220 },
new StackedStepAreaChartData { xValue = 2011, yValue = 520, yValue1 = 220 },
};
ViewData["dataSource"] = chartData;
return View();
}
public class StackedStepAreaChartData
{
public double xValue { get; set; }
public double yValue { get; set; }
public double yValue1 { get; set; }
}
private List<LineChartData1> chartData = null;
public class LineChartData1
{
public DateTime x { get; set; }
public double y { 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 Stacked StepArea type charts. This series forms the step line progress by connecting points through vertical and horizontal lines with area filled. You can use DashArray, Width and Fill properties to customize the area. Marker and DataLabel are used to represent individual data and its value.