[]
BoxWhisker chart series shows distribution of data into quartiles, highlighting the mean and the outliers. The boxes may have lines extending vertically called "whiskers". These lines indicate variability outside the upper and lower quartiles, and any point outside those lines or whiskers is considered an outlier.
They are most commonly used in statistical analysis. For example, you could use a box and whisker chart to compare medical trial results or teachers' test scores.
This topic describes how to use BoxWhisker series in your FlexChart to show distribution of data into quartiles, highlighting the mean and the outliers. To work with BoxWhisker Series, you need to create an instance of FlexChart class, which is a part of C1.Web.Mvc namespace.
The following image shows how FlexChart appears after completing the above steps:

Add a new class to the Models folder (for example: ProductSales.cs).
Add the following code to the new model to define a class which will serve as a datasource for the FlexChart.
using System.Collections.Generic;
using System.Linq;
namespace BoxWhiskerSeries.Models
{
public class ProductSales
{
public int Id { get; set; }
public string Country { get; set; }
public List<int> Sales { get; set; }
public List<int> Downloads { get; set; }
public List<int> Queries { get; set; }
public ProductSales(string country, int[] downloads, int[] sales, int[] queries)
{
Country = country;
Sales = sales.ToList();
Downloads = downloads.ToList();
Queries = queries.ToList();
}
public static List<ProductSales> GetData()
{
int[][][] stats = {
new int[][]{ new int[] { 8, 22, 24, 61, 77 }, new int[] { 30, 49, 80, 110, 130 }, new int[] { 6, 20, 32, 40, 76 } },
new int[][]{ new int[] {4, 4, 29, 39, 77}, new int[] {11, 30, 36, 99, 119}, new int[] {15, 26, 30, 34, 44} },
new int[][]{ new int[] {45, 72, 87, 89, 94}, new int[] {5, 9, 47, 60, 104}, new int[] {3, 13, 63, 66, 73} },
new int[][]{ new int[] {5, 10, 45, 51, 97}, new int[] {3, 35, 39, 56, 100}, new int[] {5, 31, 41, 76, 90} },
new int[][]{ new int[] {32, 43, 53, 78, 80}, new int[] {7, 20, 61, 74, 95}, new int[] {20, 22, 49, 80, 91} },
new int[][]{ new int[] {22, 28, 53, 63, 92}, new int[] {18, 50, 72, 100, 112}, new int[] {6, 18, 30, 42, 82} }
};
var countries = new string[] { "US", "Germany", "UK", "Japan", "France", "China" };
var data = new List<ProductSales>();
for (var i = 0; i < countries.Length; i++)
{
data.Add(new ProductSales(countries[i], stats[i][0], stats[i][1], stats[i][2]));
}
return data;
}
}
}To add a FlexChart to the application, follow these steps:
Add a new Controller
In the Solution Explorer, right click the folder Controllers.
From the context menu, select Add | Controller. The Add Scaffold dialog appears.
In the Add Scaffold dialog, follow these steps:
Select Empty MVC Controller template.
Set name of the controller (for example: BoxWhiskerController).
Click Add.
Replace the method Index() with the following method.
public ActionResult Index()
{
return View(ProductSales.GetData());
}Add a View for the Controller
From the Solution Explorer, expand the folder Controllers and double click the BoxWhiskerController.
Place the cursor inside the method Index().
Right click and select Add View. The Add View dialog appears.
In the Add View dialog, verify that the view name is Index and View engine is Razor (CSHTML).
Click Add. A view is added for the controller.
@using C1.Web.Mvc.Chart;
@using BoxWhiskerSeries.Models;
@model IEnumerable<ProductSales>
<c1-flex-chart binding="Downloads" binding-x="Country" legend-position="Top">
<c1-items-source source-collection="Model" />
<c1-flex-chart-boxwhisker name="Downloads" />
<c1-flex-chart-boxwhisker name="Sales" binding="Sales" show-outliers="true" />
<c1-flex-chart-boxwhisker name="Queries" binding="Queries" show-outliers="true" />
</c1-flex-chart>Click Build | Build Solution to build the project.
Press F5 to run the project.
Append the folder name and view name to the generated URL (for example: http://localhost:1234/ErrorBar/Index) in the address bar of the browser to see the view.
The BoxPlotData property provides precomputed IBoxPlotData statistical values to a BoxWhisker series, bypassing client-side statistical calculations during chart rendering.
When assigned an array of statistical objects, the series renders box-and-whisker elements directly from the supplied values. If BoxPlotData is unset, the chart calculates summary statistics automatically from the bound raw data.
Important: Modifying client-side raw data does not update chart elements automatically. Recalculate and reassign
BoxPlotDatato reflect changes.

Controllers
Calculate the summary statistics on the server and pass the resulting arrays to the view using ViewBag or a ViewModel:
public ActionResult Index()
{
var data = SalesAnalysis.GetData();
ViewBag.DownloadsStats = data.Select(d => GetBoxPlotData(d.Downloads)).ToArray();
ViewBag.SalesStats = data.Select(d => GetBoxPlotData(d.Sales)).ToArray();
return View(data);
}
private static BoxPlotData GetBoxPlotData(IList<int> values)
{
var sorted = values.OrderBy(v => v).Select(v => (double)v).ToList();
var q1 = Quantile(sorted, 0.25);
var q3 = Quantile(sorted, 0.75);
var iqr = q3 - q1;
var lower = q1 - 1.5 * iqr;
var upper = q3 + 1.5 * iqr;
var inRange = sorted.Where(v => v >= lower && v <= upper).ToList();
var min = inRange.Count > 0 ? inRange.First() : sorted.First();
var max = inRange.Count > 0 ? inRange.Last() : sorted.Last();
return new BoxPlotData
{
Min = min,
Max = max,
Mean = sorted.Average(),
FirstQuartile = q1,
ThirdQuartile = q3,
Median = Quantile(sorted, 0.5),
OutlierPoints = sorted.Where(v => v < lower || v > upper).ToArray(),
InnerPoints = sorted.Where(v => v > min && v < max).ToArray()
};
}
private static double Quantile(IList<double> sorted, double q)
{
var pos = (sorted.Count - 1) * q;
var lo = (int)Math.Floor(pos);
var hi = (int)Math.Ceiling(pos);
return lo == hi ? sorted[lo] : sorted[lo] + (sorted[hi] - sorted[lo]) * (pos - lo);
}ASP.NET Core View
Configure box-plot-data on each target series using Tag Helpers:
@model IEnumerable<SalesAnalysis>
@{
var downloadsStats = ViewBag.DownloadsStats as BoxPlotData[];
var salesStats = ViewBag.SalesStats as BoxPlotData[];
}
<c1-flex-chart id="boxPlotDataChart" binding="Downloads" binding-x="Country">
<c1-items-source source-collection="Model"></c1-items-source>
@* statistics prepared on the server, used as-is *@
<c1-flex-chart-boxwhisker name="Downloads" show-outliers="true"
box-plot-data="downloadsStats"></c1-flex-chart-boxwhisker>
<c1-flex-chart-boxwhisker binding="Sales" name="Sales" show-outliers="true"
box-plot-data="salesStats"></c1-flex-chart-boxwhisker>
@* no statistics supplied: falls back to the raw data *@
<c1-flex-chart-boxwhisker binding="Queries" name="Queries" show-outliers="true"></c1-flex-chart-boxwhisker>
</c1-flex-chart>