Skip to content
IzzyBlazor

Enter all results ↑ ↓ move Esc close

Box plot

Since 0.1.0-alpha.23
Compares how values spread across groups: each group's median, middle half, range and outliers.

Use 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

Delivery time by carrier, March
Arrow keys move between values; Escape hides the tooltip.

Code

Usage.razor
@* 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>

@code {
    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:

bash
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

Delivery time by carrier and service, March
  • Standard
  • Express
Arrow keys move between values; Escape hides the tooltip.

Code

BoxPlotGrouped.razor
@* 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>

@code {
    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

API response time by region, last 7 days (whiskers: 5th to 95th percentile)
Arrow keys move between values; Escape hides the tooltip.

Code

BoxPlotSummary.razor
@* 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>

@code {
    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: its Low, Q1, Median, Q3 and High, such as a database's percentiles over millions of rows.

Mode support

What works in each mode, Box plot
FeatureStaticInteractive
A box per group, worked out from raw values: quartiles, median and whiskersYesYes
Tukey whiskers with outliers drawn as circles, or whiskers to the minimum and maximumYesYes
The mean marked with a diamondYesYes
Boxes from numbers already worked out, such as a database's percentilesYesYes
Boxes split by a group, side by side within each argumentYesYes
Upright, or lying across for long namesYesYes
Each box's numbers in its tooltip and the tableYesYes
A table of the values behind a "Show data" buttonYesYes
Tooltips on hover and from the keyboardYesYes

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

ChartBoxPlotSeries parameters
PropTypeDefault
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.ChartWhiskersChartWhiskers.Tukey
ShowMeanMarks each box's mean with a diamond, and says it in the tooltip and data table.boolfalse
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).DataAggregateDataAggregate.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.ChartLabelsChartLabels.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).ChartLabelOverlapChartLabelOverlap.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.ChartTrendChartTrend.None
TrendOrderA polynomial trend's order, 2 (a parabola) to 6.int2
TrendPeriodHow many values a moving average takes in, 2 or more.int3
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.boolfalse

Connection lost

Rejoining the server…