Example of Step Line in ASP.NET Core Charts Control
This Step Line Chart example visualizes the global best-selling albums by year from 2001 to 2024.
${x}
@Html.UiChart(new UiChartOptions
{
Id = "stepLineChart",
Title = "Worldwide Best-Selling Albums by Year",
SubTitle = "Source: wikipedia.org",
Data = (IEnumerable<object>)ViewData["StepLineData"],
Tooltip = new UiChartTooltip { Enable = true, ShowNearestTooltip = true, EnableHighlight = true, Template = "#tipStepLine" },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Double, ShowGridLines = false, Minimum = 2006, Maximum = 2025, Interval = 3 },
PrimaryYAxis = new UiChartAxis { LabelFormat = "{value}", Minimum = 0, Maximum = 20, Interval = 4, Title = "Sales in million" },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.StepLine, Width = 3, XName = "X", YName = "Y", Opacity = 1, ShowDataLabel = true }
}
})
<template id="tipStepLine"><b>${x}</b></template>
@Html.UiChart(new UiChartOptions
{
Id = "stepLineChart",
Title = "Worldwide Best-Selling Albums by Year",
SubTitle = "Source: wikipedia.org",
Data = (IEnumerable<object>)ViewData["StepLineData"],
Tooltip = new UiChartTooltip { Enable = true, ShowNearestTooltip = true, EnableHighlight = true, Template = "#tipStepLine" },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Double, ShowGridLines = false, Minimum = 2006, Maximum = 2025, Interval = 3 },
PrimaryYAxis = new UiChartAxis { LabelFormat = "{value}", Minimum = 0, Maximum = 20, Interval = 4, Title = "Sales in million" },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.StepLine, Width = 3, XName = "X", YName = "Y", Opacity = 1, ShowDataLabel = 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/StepLine.cshtml; it draws what ViewData holds.
public ActionResult StepLine()
{
List<StepLineChartData> StepLineData = new List<StepLineChartData>
{
new StepLineChartData { X = 2007, Y = 6.0, Album = "High School Musical 2", Artist = "Various Artists" },
new StepLineChartData { X = 2007, Y = 6.0, Album = "High School Musical 2", Artist = "Various Artists" },
new StepLineChartData { X = 2008, Y = 6.8, Album = "Viva la Vida or Death and All His Friends", Artist = "Coldplay" },
new StepLineChartData { X = 2009, Y = 8.3, Album = "I Dreamed a Dream", Artist = "Susan Boyle" },
new StepLineChartData { X = 2010, Y = 5.7, Album = "Recovery", Artist = "Eminem" },
new StepLineChartData { X = 2011, Y = 18.1, Album = "21", Artist = "Adele" },
new StepLineChartData { X = 2012, Y = 8.3, Album = "21", Artist = "Adele" },
new StepLineChartData { X = 2013, Y = 4.0, Album = "Midnight Memories", Artist = "One Direction" },
new StepLineChartData { X = 2014, Y = 10.0, Album = "Frozen", Artist = "Various Artists" },
new StepLineChartData { X = 2015, Y = 17.4, Album = "25", Artist = "Adele" },
new StepLineChartData { X = 2016, Y = 2.5, Album = "Lemonade", Artist = "Beyoncé" },
new StepLineChartData { X = 2017, Y = 6.1, Album = "÷", Artist = "Ed Sheeran" },
new StepLineChartData { X = 2018, Y = 3.5, Album = "The Greatest Showman", Artist = "Hugh Jackman & Various Artists" },
new StepLineChartData { X = 2019, Y = 3.3, Album = "5x20 All the Best!! 1999–2019", Artist = "Arashi" },
new StepLineChartData { X = 2020, Y = 4.8, Album = "Map of the Soul: 7", Artist = "BTS" },
new StepLineChartData { X = 2021, Y = 4.68, Album = "30", Artist = "Adele" },
new StepLineChartData { X = 2022, Y = 7.2, Album = "Greatest Works of Art", Artist = "Jay Chou" },
new StepLineChartData { X = 2023, Y = 6.4, Album = "FML", Artist = "Seventeen" },
new StepLineChartData { X = 2024, Y = 5.6, Album = "The Tortured Poets Department", Artist = "Taylor Swift" }
};
ViewData["StepLineData"] = StepLineData;
return View();
}
public class StepLineChartData
{
public double X { get; set; }
public double Y { get; set; }
public string Artist { get; set; }
public string Album { get; set; }
}
}
}
@* Program.cs *@
builder.Services.AddControllersWithViews().AddLumenUIJson();
builder.Services.AddLumenUI();
// ...
app.UseLumenUI();
@* Views/_ViewImports.cshtml *@
@using Lumen.UI.Mvc
@addTagHelper *, Lumen.UI.Core
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/css/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@await RenderSectionAsync("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 a step line type chart. This chart forms a step-like progression by connecting points using vertical and horizontal lines. Markers are used to represent individual data points and their values.
Tooltip is enabled in this example. To see the tooltip in action, hover over or tap on the chart.