Box plot
Since 0.1.0-alpha.23Use box plots to compare how values spread across many groups, such as delivery times by carrier. A box is a summary, so it hides the shape. Two peaks look the same as one smooth spread. For large groups, use a violin plot to show the shape.
A box plot
ChartBoxPlotSeries makes a box from the Values of the items that share an Argument, here a month of parcels by carrier.
Static
Preview
| Carrier | Median | Lower quartile | Upper quartile | Lower whisker | Upper whisker | Values | Outliers |
|---|---|---|---|---|---|---|---|
| Northwind Post | 2.5 | 2 | 3 | 1.1 | 4.4 | 180 | 4 |
| Parcelwise | 3.3 | 2.4 | 4.3 | 1.4 | 7.1 | 140 | 4 |
| Swift Freight | 1.8 | 1.5 | 2.2 | 0.7 | 3.2 | 160 | 5 |
| Coastline Express | 3.6 | 2.7 | 4.9 | 1.4 | 8.2 | 120 | 4 |
Code
@* Days from order to delivery for a month's parcels with four carriers: most arrive in two to
four days, and the parcels held up by a missed scan or a weather delay show as outliers. *@
<Chart Items="_parcels" Argument="p => p.Carrier" Title="Delivery time by carrier, March">
<ChartValueAxis Title="Days from order to delivery" />
<ChartBoxPlotSeries Value="p => p.Days" Name="Delivery time" />
</Chart>
{
private record Parcel(string Carrier, double Days);
// Sample data: each carrier's typical time and spread, skewed late, with a few parcels delayed.
private readonly Parcel[] _parcels =
[
.. Parcels("Northwind Post", 2.4, 0.3, 0.03, 180, seed: 1),
.. Parcels("Parcelwise", 3.1, 0.35, 0.05, 140, seed: 2),
.. Parcels("Swift Freight", 1.8, 0.3, 0.02, 160, seed: 3),
.. Parcels("Coastline Express", 3.6, 0.35, 0.06, 120, seed: 4),
];
private static IEnumerable<Parcel> Parcels(string carrier, double median, double spread, double delayed, int count, int seed)
{
var random = new Random(seed);
return Enumerable.Range(0, count).Select(_ =>
{
var normal = Math.Sqrt(-2 * Math.Log(1 - random.NextDouble())) * Math.Cos(2 * Math.PI * random.NextDouble());
var days = median * Math.Exp(spread * normal) + (random.NextDouble() < delayed ? 1.5 + random.NextDouble() * 3 : 0);
return new Parcel(carrier, Math.Round(days, 1));
}).ToList();
}
}Add this example to a page with the izzy CLI:
izzy add component ChartBoxPlotSeries --at <file>:<line>Each box runs from the first quartile to the third, so it holds the middle half of the values, with a line at the median.
The whiskers reach the furthest values within 1.5 times the box's height of its ends (Tukey's rule). Values past them are outliers, drawn as circles: here the parcels a missed scan or a storm held up. Whiskers="ChartWhiskers.MinMax" runs them to the smallest and largest values instead, with no outliers.
Quartiles are interpolated between the sorted values, as Excel's QUARTILE.INC works them out.
Boxes split by a group
SeriesBy splits each argument's values by a group, here standard and express service, and draws their boxes side by side. ShowMean marks each box's mean with a diamond, which sits above the median when a few late parcels pull it up.
Static
Preview
- Standard
- Express
| Carrier | Service | Median | Lower quartile | Upper quartile | Lower whisker | Upper whisker | Mean | Values | Outliers |
|---|---|---|---|---|---|---|---|---|---|
| Northwind Post | Standard | 2.6 | 2.03 | 3.1 | 1.1 | 4.7 | 2.66 | 134 | 1 |
| Northwind Post | Express | 1.2 | 1 | 1.4 | 0.7 | 1.8 | 1.29 | 66 | 5 |
| Parcelwise | Standard | 3.3 | 2.5 | 4.18 | 1.7 | 6.1 | 3.56 | 134 | 7 |
| Parcelwise | Express | 1.55 | 1.2 | 1.98 | 0.8 | 2.4 | 1.64 | 66 | 2 |
| Swift Freight | Standard | 1.9 | 1.53 | 2.2 | 0.7 | 3.1 | 1.94 | 134 | 2 |
| Swift Freight | Express | 0.9 | 0.8 | 1.1 | 0.4 | 1.5 | 0.96 | 66 | 5 |
| Coastline Express | Standard | 3.5 | 2.9 | 4.5 | 1.6 | 6.5 | 3.88 | 134 | 7 |
| Coastline Express | Express | 1.75 | 1.5 | 2.2 | 0.8 | 3.1 | 1.95 | 66 | 4 |
Code
@* The same carriers' times for standard and express service: a box for each, side by side, with
each box's mean marked as well as its median. *@
<Chart Items="_parcels" Argument="p => p.Carrier" Title="Delivery time by carrier and service, March">
<ChartValueAxis Title="Days from order to delivery" />
<ChartBoxPlotSeries Value="p => p.Days" SeriesBy="p => p.Service" ShowMean />
</Chart>
{
private record Parcel(string Carrier, string Service, double Days);
// Sample data: express takes about half as long as standard, with fewer delays.
private readonly Parcel[] _parcels =
[
.. Parcels("Northwind Post", 2.4, 0.03, seed: 1),
.. Parcels("Parcelwise", 3.1, 0.05, seed: 2),
.. Parcels("Swift Freight", 1.8, 0.02, seed: 3),
.. Parcels("Coastline Express", 3.6, 0.06, seed: 4),
];
private static IEnumerable<Parcel> Parcels(string carrier, double median, double delayed, int seed)
{
var random = new Random(seed);
return Enumerable.Range(0, 200).Select(k =>
{
var express = k % 3 == 2;
var normal = Math.Sqrt(-2 * Math.Log(1 - random.NextDouble())) * Math.Cos(2 * Math.PI * random.NextDouble());
var days = (express ? median * 0.5 : median) * Math.Exp(0.3 * normal)
+ (random.NextDouble() < (express ? delayed / 2 : delayed) ? 1.5 + random.NextDouble() * 3 : 0);
return new Parcel(carrier, express ? "Express" : "Standard", Math.Round(days, 1));
}).ToList();
}
}With long names, the chart's Orientation="Orientation.Horizontal" lays the boxes across.
A box plot's chart holds only box plot series, and doesn't stack or zoom.
Boxes from a summary
ChartBoxSummarySeries draws each item as one box from numbers already worked out: its Low, Q1, Median, Q3 and High. Use it when a database or monitoring tool summarizes the values, here a week of an API's requests by region.
Static
Preview
| Region | Median | Lower quartile | Upper quartile | Lower whisker | Upper whisker | Mean |
|---|---|---|---|---|---|---|
| US East | 64 | 52 | 82 | 38 | 141 | 74 |
| US West | 73 | 60 | 94 | 44 | 166 | 86 |
| Europe | 83 | 68 | 108 | 51 | 192 | 99 |
| Asia Pacific | 142 | 117 | 186 | 88 | 334 | 171 |
| South America | 158 | 131 | 207 | 97 | 389 | 192 |
Code
@* A week of an API's response times by region, as a monitoring database reports them: percentiles
and a mean over millions of requests, not the requests themselves. The whiskers are the 5th and
95th percentiles, as the title says. *@
<Chart Items="_regions" Argument="r => r.Region" Title="API response time by region, last 7 days (whiskers: 5th to 95th percentile)">
<ChartValueAxis Title="Milliseconds" />
<ChartBoxSummarySeries Low="r => r.P5" Q1="r => r.P25" Median="r => r.P50" Q3="r => r.P75" High="r => r.P95"
Mean="r => r.Mean" Name="Response time" />
</Chart>
{
private record RegionLatency(string Region, double P5, double P25, double P50, double P75, double P95, double Mean);
// Sample data: each region's percentiles, the mean above the median, as a long tail pulls it.
private readonly RegionLatency[] _regions =
[
new("US East", 38, 52, 64, 82, 141, 74),
new("US West", 44, 60, 73, 94, 166, 86),
new("Europe", 51, 68, 83, 108, 192, 99),
new("Asia Pacific", 88, 117, 142, 186, 334, 171),
new("South America", 97, 131, 158, 207, 389, 192),
];
}The whiskers end at Low and High, whatever they stand for: here the 5th and 95th percentiles. Say which in the title, since a reader would otherwise take them for Tukey's whiskers.
Mean marks each box's mean with a diamond. Outliers takes a list of numbers on each item, drawn as circles past the whiskers.
SeriesBy puts the boxes of items that share an Argument side by side; each split series takes one item per box.
Details
Each box shows the quartiles and median, with whiskers and outliers by Whiskers. SeriesBy puts a box per group side by side; the chart's Orientation="Orientation.Horizontal" lays them across. A box plot's chart holds only box plot series. For numbers already worked out, such as by a database, use ChartBoxSummarySeries<T>.
Parts
Written inside ChartBoxPlotSeries. The API page lists their parameters.
ChartBoxSummarySeries<TItem>: draws a box plot from numbers already worked out, one item per box: itsLow,Q1,Median,Q3andHigh, such as a database's percentiles over millions of rows.
Mode support
| Feature | Static | Interactive |
|---|---|---|
| A box per group, worked out from raw values: quartiles, median and whiskers | Yes | Yes |
| Tukey whiskers with outliers drawn as circles, or whiskers to the minimum and maximum | Yes | Yes |
| The mean marked with a diamond | Yes | Yes |
| Boxes from numbers already worked out, such as a database's percentiles | Yes | Yes |
| Boxes split by a group, side by side within each argument | Yes | Yes |
| Upright, or lying across for long names | Yes | Yes |
| Each box's numbers in its tooltip and the table | Yes | Yes |
| A table of the values behind a "Show data" button | Yes | Yes |
| Tooltips on hover and from the keyboard | Yes | Yes |
Static: static server-side rendering, with no circuit and no WebAssembly. Interactive: Server, WebAssembly or Auto.
Without JavaScript
Every page starts as plain HTML: before IzzyBlazor's script loads on a static page, while an interactive page prerenders, and with JavaScript off.
- Tooltips on hover and from the keyboard: waits for the script
Parameters
| Prop | Type | Default |
|---|---|---|
ValueEach item's value, such as d => d.Days: a number, or null to leave the item out. | Expression<Func<TItem, object?>> | Required |
WhiskersHow far the whiskers reach: ChartWhiskers.Tukey (the default), to the furthest values within 1.5 times the box's height, with outliers past them; or ChartWhiskers.MinMax, to the smallest and largest values. | ChartWhiskers | ChartWhiskers.Tukey |
ShowMeanMarks each box's mean with a diamond, and says it in the tooltip and data table. | bool | false |
AggregateWith ChartDrillLevel<T>s, how each level adds up its items' values: DataAggregate.Sum (the default), DataAggregate.Avg, DataAggregate.Min, DataAggregate.Max or DataAggregate.Count (the items with a value). | DataAggregate | DataAggregate.Sum |
NameThe series' name, in the legend, the data table and each value's description. | string? | computed |
SeriesBySplits the series into one per value of this, such as p => p.Device: each draws only its own items' values, is named by its value, and takes the next color and marker, in the order the values first appear. | Expression<Func<TItem, object?>>? | |
ColorA CSS color, such as var(--ib-color-danger) or #0f766e. | string? | computed |
LabelsWrites each value beside its bar or point. | ChartLabels | ChartLabels.None |
LabelFormatA .NET format string for this series' labels, such as C0. | string? | computed |
LabelTextWhat each label says in place of its value, such as r => r.Region to name each bubble or point. | Expression<Func<TItem, object?>>? | |
LabelOverlapWhat labels do when they'd overlap others: left out at those widths (ChartLabelOverlap.Hide, the default), or shown anyway (ChartLabelOverlap.Show). | ChartLabelOverlap | ChartLabelOverlap.Hide |
TrendDraws a trend through the values: a dashed line in the series' color, named "Revenue trend" (a moving average "Revenue, 7-day average") in the legend, tooltips and data table. | ChartTrend | ChartTrend.None |
TrendOrderA polynomial trend's order, 2 (a parabola) to 6. | int | 2 |
TrendPeriodHow many values a moving average takes in, 2 or more. | int | 3 |
TrendColorThe trend's CSS color, such as var(--ib-color-danger), used as given. | string? | computed |
ValueAxisThe Name of the value axis the series is read off, for a measure in other units on a second axis at the end side, such as "margin". | string? | computed |
HiddenStarts with the series hidden: the chart is drawn as if it weren't there, and it keeps its place in the legend, to show it again, and in the data table. | bool | false |