Example of Overview in ASP.NET Core Charts Control
This sample shows how different chart types can help visualize data and make informed decisions.
Sales - Yearly Performance
Product Wise Sales - 2024
Monthly Sales for 2024
@Html.UiChart(new UiChartOptions
{
Id = "overviewColumnChart",
Data = (IEnumerable<object>)ViewData["columnSource"],
Height = "330px",
Legend = new UiChartLegend { Visible = true, Position = UiChartLegendPosition.Bottom, EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category, Interval = 1, ShowGridLines = false },
PrimaryYAxis = new UiChartAxis { LabelFormat = "{value}%", Minimum = 0, Maximum = 100 },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Column, XName = "Period", YName = "OnlinePercentage", Name = "Online", Fill = "#2485FA", CornerRadius = 4, ShowDataLabel = true, DataLabelPosition = UiChartLabelPosition.Inside },
new UiChartSeries { Type = UiChartSeriesType.Column, XName = "Period", YName = "RetailPercentage", Name = "Retail", Fill = "#FEC200", CornerRadius = 4, ShowDataLabel = true, DataLabelPosition = UiChartLabelPosition.Inside }
}
})
@Html.UiChart(new UiChartOptions
{
Id = "overviewPieChart",
Data = (IEnumerable<object>)ViewData["pieSource"],
Height = "330px",
Legend = new UiChartLegend { Visible = false },
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true },
Palette = (string[])ViewData["palettes"],
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Doughnut, XName = "Product", YName = "Percentage", InnerRadius = "40%", Radius = "75%", StartAngle = 270, ShowDataLabel = true, DataLabelTemplate = "${Text}", DataLabelPosition = UiChartLabelPosition.Outside }
}
})
@Html.UiChart(new UiChartOptions
{
Id = "overviewSplineChart",
Data = (IEnumerable<object>)ViewData["splineSource"],
Height = "330px",
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true, ShowNearestTooltip = true },
Legend = new UiChartLegend { EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category, ShowGridLines = false },
PrimaryYAxis = new UiChartAxis { LabelFormat = "${value}", Minimum = 0, Maximum = 12000 },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.SplineArea, XName = "Period", YName = "OnlinePercentage", Name = "Online", Fill = "#2485FA", Opacity = 0.3, Width = 3 },
new UiChartSeries { Type = UiChartSeriesType.SplineArea, XName = "Period", YName = "RetailPercentage", Name = "Retail", Fill = "#FEC200", Opacity = 0.3, Width = 3 }
}
})
<div class="overview-dashboard">
<div class="overview-panel overview-wide">
<div class="overview-title">Sales - Yearly Performance</div>
@Html.UiChart(new UiChartOptions
{
Id = "overviewColumnChart",
Data = (IEnumerable<object>)ViewData["columnSource"],
Height = "330px",
Legend = new UiChartLegend { Visible = true, Position = UiChartLegendPosition.Bottom, EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category, Interval = 1, ShowGridLines = false },
PrimaryYAxis = new UiChartAxis { LabelFormat = "{value}%", Minimum = 0, Maximum = 100 },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Column, XName = "Period", YName = "OnlinePercentage", Name = "Online", Fill = "#2485FA", CornerRadius = 4, ShowDataLabel = true, DataLabelPosition = UiChartLabelPosition.Inside },
new UiChartSeries { Type = UiChartSeriesType.Column, XName = "Period", YName = "RetailPercentage", Name = "Retail", Fill = "#FEC200", CornerRadius = 4, ShowDataLabel = true, DataLabelPosition = UiChartLabelPosition.Inside }
}
})
</div>
<div class="overview-panel overview-narrow">
<div class="overview-title">Product Wise Sales - 2024</div>
@Html.UiChart(new UiChartOptions
{
Id = "overviewPieChart",
Data = (IEnumerable<object>)ViewData["pieSource"],
Height = "330px",
Legend = new UiChartLegend { Visible = false },
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true },
Palette = (string[])ViewData["palettes"],
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Doughnut, XName = "Product", YName = "Percentage", InnerRadius = "40%", Radius = "75%", StartAngle = 270, ShowDataLabel = true, DataLabelTemplate = "${Text}", DataLabelPosition = UiChartLabelPosition.Outside }
}
})
</div>
<div class="overview-panel overview-full">
<div class="overview-title">Monthly Sales for 2024</div>
@Html.UiChart(new UiChartOptions
{
Id = "overviewSplineChart",
Data = (IEnumerable<object>)ViewData["splineSource"],
Height = "330px",
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true, ShowNearestTooltip = true },
Legend = new UiChartLegend { EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category, ShowGridLines = false },
PrimaryYAxis = new UiChartAxis { LabelFormat = "${value}", Minimum = 0, Maximum = 12000 },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.SplineArea, XName = "Period", YName = "OnlinePercentage", Name = "Online", Fill = "#2485FA", Opacity = 0.3, Width = 3 },
new UiChartSeries { Type = UiChartSeriesType.SplineArea, XName = "Period", YName = "RetailPercentage", Name = "Retail", Fill = "#FEC200", Opacity = 0.3, Width = 3 }
}
})
</div>
</div>
<style>
.overview-dashboard { display: grid; grid-template-columns: repeat(8, 1fr); gap: 15px; padding: 20px; }
.overview-panel { min-width: 0; border-radius: 8px; box-shadow: 0 1px 4px rgba(0, 0, 0, .18); background: var(--demo-surface, #fff); padding: 6px 12px 10px; }
.overview-wide { grid-column: span 5; }
.overview-narrow { grid-column: span 3; }
.overview-full { grid-column: span 8; }
.overview-title { text-align: center; font-size: 15px; font-weight: bold; color: #737373; padding: 14px 0 6px; }
@@media (max-width: 800px) { .overview-wide, .overview-narrow, .overview-full { grid-column: span 8; } }
</style>
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/Overview.cshtml; it draws what ViewData holds.
public ActionResult Overview()
{
ViewData["columnSource"] = new List<LayoutData>
{
new LayoutData { Period = "2020", OnlinePercentage = 60, RetailPercentage = 40 },
new LayoutData { Period = "2021", OnlinePercentage = 56, RetailPercentage = 44 },
new LayoutData { Period = "2022", OnlinePercentage = 71, RetailPercentage = 29 },
new LayoutData { Period = "2023", OnlinePercentage = 85, RetailPercentage = 15 },
new LayoutData { Period = "2024", OnlinePercentage = 73, RetailPercentage = 27 }
};
ViewData["pieSource"] = new List<LayoutPieData>
{
new LayoutPieData { Product = "TV : 30 (12%)", Percentage = 12, Text = "TV, 30\n12%" },
new LayoutPieData { Product = "PC : 20 (8%)", Percentage = 8, Text = "PC, 20\n8%" },
new LayoutPieData { Product = "Laptop : 40 (16%)", Percentage = 16, Text = "Laptop, 40\n16%" },
new LayoutPieData { Product = "Mobile : 90 (36%)", Percentage = 36, Text = "Mobile, 90\n36%" },
new LayoutPieData { Product = "Camera : 27 (11%)", Percentage = 11, Text = "Camera, 27\n11%" }
};
ViewData["splineSource"] = new List<LayoutData>
{
new LayoutData { Period = "Jan", OnlinePercentage = 3600, RetailPercentage = 6400 },
new LayoutData { Period = "Feb", OnlinePercentage = 6200, RetailPercentage = 5300 },
new LayoutData { Period = "Mar", OnlinePercentage = 8100, RetailPercentage = 4900 },
new LayoutData { Period = "Apr", OnlinePercentage = 5900, RetailPercentage = 5300 },
new LayoutData { Period = "May", OnlinePercentage = 8900, RetailPercentage = 4200 },
new LayoutData { Period = "Jun", OnlinePercentage = 7200, RetailPercentage = 6500 },
new LayoutData { Period = "Jul", OnlinePercentage = 4300, RetailPercentage = 7900 },
new LayoutData { Period = "Aug", OnlinePercentage = 4600, RetailPercentage = 3800 },
new LayoutData { Period = "Sep", OnlinePercentage = 5500, RetailPercentage = 6800 },
new LayoutData { Period = "Oct", OnlinePercentage = 6350, RetailPercentage = 3400 },
new LayoutData { Period = "Nov", OnlinePercentage = 5700, RetailPercentage = 6400 },
new LayoutData { Period = "Dec", OnlinePercentage = 8000, RetailPercentage = 6800 }
};
ViewData["palettes"] = new string[] { "#61EFCD", "#CDDE1F", "#FEC200", "#CA765A", "#2485FA", "#F57D7D", "#C152D2", "#8854D9", "#3D4EB8", "#00BCD7" };
return View();
}
/// <summary>One period of the Overview sample's column and area charts: the share of online and retail sales.</summary>
public class LayoutData
{
public string Period { get; set; }
public double OnlinePercentage { get; set; }
public double RetailPercentage { get; set; }
}
/// <summary>One slice of the Overview sample's doughnut: the product, its share and the label text.</summary>
public class LayoutPieData
{
public string Product { get; set; }
public double Percentage { get; set; }
public string Text { 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. *@
The ASP.NET MVC Chart is a well-crafted charting component to visualize data. In this example, you will see how to render and configure line, column, and pie charts with different features such as highlight, legend, tooltip and annotation.
Tooltip is enabled in this example. To see the tooltip in action, hover over or tap on the chart.