Example of Error Bar in ASP.NET Core Charts Control
This example draws error bars through the points of a series, with a fixed, a percentage, a deviation or a custom size.
@Html.UiChart(new UiChartOptions
{
Id = "errorFixedChart",
Data = (IEnumerable<object>)ViewData["ChartData"],
Height = "300px",
Title = "Fixed: 3,000 up and down",
PrimaryYAxis = new UiChartAxis { LabelFormat = "N0" },
Series = new List<UiChartSeries>
{
new UiChartSeries
{
Type = UiChartSeriesType.Column, XName = "MonthName", YName = "Online", Name = "Online",
ErrorBar = new UiChartErrorBar { Type = UiChartErrorBarType.Fixed, Error = 3000 }
}
}
})
@Html.UiChart(new UiChartOptions
{
Id = "errorPercentChart",
Data = (IEnumerable<object>)ViewData["ChartData"],
Height = "300px",
Title = "Percentage: 10 %, upward only",
PrimaryYAxis = new UiChartAxis { LabelFormat = "N0" },
Series = new List<UiChartSeries>
{
new UiChartSeries
{
Type = UiChartSeriesType.Line, XName = "MonthName", YName = "Retail", Name = "Retail", ShowMarker = true,
ErrorBar = new UiChartErrorBar { Type = UiChartErrorBarType.Percentage, Error = 10, Direction = UiChartErrorBarDirection.Plus, Color = "#d13438" }
}
}
})
@Html.UiChart(new UiChartOptions
{
Id = "errorDeviationChart",
Data = (IEnumerable<object>)ViewData["ChartData"],
Height = "300px",
Title = "Standard deviation of the series",
PrimaryYAxis = new UiChartAxis { LabelFormat = "N0" },
Series = new List<UiChartSeries>
{
new UiChartSeries
{
Type = UiChartSeriesType.Scatter, XName = "MonthName", YName = "Wholesale", Name = "Wholesale",
ErrorBar = new UiChartErrorBar { Type = UiChartErrorBarType.StandardDeviation, Error = 1, CapLength = 16 }
}
}
})
@Html.UiChart(new UiChartOptions
{
Id = "errorCustomChart",
Data = (IEnumerable<object>)ViewData["ChartData2"],
Height = "300px",
Title = "Custom: 5 % above, 15 % below",
PrimaryYAxis = new UiChartAxis { LabelFormat = "N0" },
Series = new List<UiChartSeries>
{
new UiChartSeries
{
Type = UiChartSeriesType.Spline, XName = "MonthName", YName = "Online", Name = "Online", ShowMarker = true,
ErrorBar = new UiChartErrorBar { Type = UiChartErrorBarType.Custom, PositiveErrorField = "Above", NegativeErrorField = "Below" }
}
}
})
@using System.Linq
@using Lumen.UI.Mvc.Demo.Models
<div class="row g-3">
<div class="col-12 col-xl-6">
@Html.UiChart(new UiChartOptions
{
Id = "errorFixedChart",
Data = (IEnumerable<object>)ViewData["ChartData"],
Height = "300px",
Title = "Fixed: 3,000 up and down",
PrimaryYAxis = new UiChartAxis { LabelFormat = "N0" },
Series = new List<UiChartSeries>
{
new UiChartSeries
{
Type = UiChartSeriesType.Column, XName = "MonthName", YName = "Online", Name = "Online",
ErrorBar = new UiChartErrorBar { Type = UiChartErrorBarType.Fixed, Error = 3000 }
}
}
})
</div>
<div class="col-12 col-xl-6">
@Html.UiChart(new UiChartOptions
{
Id = "errorPercentChart",
Data = (IEnumerable<object>)ViewData["ChartData"],
Height = "300px",
Title = "Percentage: 10 %, upward only",
PrimaryYAxis = new UiChartAxis { LabelFormat = "N0" },
Series = new List<UiChartSeries>
{
new UiChartSeries
{
Type = UiChartSeriesType.Line, XName = "MonthName", YName = "Retail", Name = "Retail", ShowMarker = true,
ErrorBar = new UiChartErrorBar { Type = UiChartErrorBarType.Percentage, Error = 10, Direction = UiChartErrorBarDirection.Plus, Color = "#d13438" }
}
}
})
</div>
<div class="col-12 col-xl-6">
@Html.UiChart(new UiChartOptions
{
Id = "errorDeviationChart",
Data = (IEnumerable<object>)ViewData["ChartData"],
Height = "300px",
Title = "Standard deviation of the series",
PrimaryYAxis = new UiChartAxis { LabelFormat = "N0" },
Series = new List<UiChartSeries>
{
new UiChartSeries
{
Type = UiChartSeriesType.Scatter, XName = "MonthName", YName = "Wholesale", Name = "Wholesale",
ErrorBar = new UiChartErrorBar { Type = UiChartErrorBarType.StandardDeviation, Error = 1, CapLength = 16 }
}
}
})
</div>
<div class="col-12 col-xl-6">
@Html.UiChart(new UiChartOptions
{
Id = "errorCustomChart",
Data = (IEnumerable<object>)ViewData["ChartData2"],
Height = "300px",
Title = "Custom: 5 % above, 15 % below",
PrimaryYAxis = new UiChartAxis { LabelFormat = "N0" },
Series = new List<UiChartSeries>
{
new UiChartSeries
{
Type = UiChartSeriesType.Spline, XName = "MonthName", YName = "Online", Name = "Online", ShowMarker = true,
ErrorBar = new UiChartErrorBar { Type = UiChartErrorBarType.Custom, PositiveErrorField = "Above", NegativeErrorField = "Below" }
}
}
})
</div>
</div>
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/ErrorBar.cshtml; it draws what ViewData holds.
public ActionResult ErrorBar()
{
ViewData["ChartData"] = MonthlySalesData();
ViewData["ChartData2"] = MonthlySalesData().Select(m => new { m.MonthName, m.Online, Above = m.Online * 0.05, Below = m.Online * 0.15 }).ToList();
return View();
}
/// <summary>The sales of one month per channel: the rows of the Line, Column and Area samples.</summary>
public class SalesData
{
public string MonthName { get; set; }
public double Online { get; set; }
public double Retail { get; set; }
public double Wholesale { get; set; }
public double Target { get; set; }
}
private static List<SalesData> MonthlySalesData()
{
var list = new List<SalesData>();
for (int m = 0; m < 12; m++)
{
list.Add(new SalesData
{
MonthName = new DateTime(2026, 1, 1).AddMonths(m).ToString("MMM"),
Online = 18000 + m * 1400 + (m % 3) * 2100,
Retail = 26000 + (m % 4) * 1800 - m * 300,
Wholesale = 12000 + m * 900 + (m % 2) * 3000,
Target = 60000 + m * 1500
});
}
return list;
}
}
}
@* 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. *@
ErrorBar on a series draws a whisker with caps through each point. Type chooses the size: Fixed, Percentage, StandardDeviation, StandardError, or Custom from two fields of the row. The whiskers count in the range of the value axis.