Histogram
Since 0.1.0-alpha.23Use a histogram for a first look at one measure, such as delivery times. It shows where values bunch, whether they lean to one side, and whether there are two peaks. The bin width changes the picture, so try a few. To compare more than three groups, use box plots.
A histogram
ChartHistogramSeries cuts each item's Value into bins and draws a bar for how many fall in each. The chart takes no Argument: the bins are its axis, here a day's page load times.
Static
Preview
| Largest Contentful Paint (seconds) | Visits |
|---|---|
| 0.0 – 0.5 | 1 |
| 0.5 – 1.0 | 99 |
| 1.0 – 1.5 | 181 |
| 1.5 – 2.0 | 137 |
| 2.0 – 2.5 | 86 |
| 2.5 – 3.0 | 48 |
| 3.0 – 3.5 | 25 |
| 3.5 – 4.0 | 15 |
| 4.0 – 4.5 | 5 |
| 4.5 – 5.0 | 2 |
| 5.0 – 5.5 | 0 |
| 5.5 – 6.0 | 1 |
Code
@* How long the main content of a store's product pages took to show (Largest Contentful Paint)
over a day's 600 visits: most within 2.5 seconds, Google's "good" mark, with a long tail. *@
<Chart Items="_visits" Title="Product page load time, March 9">
<ChartArgumentAxis Title="Largest Contentful Paint (seconds)" />
<ChartValueAxis Title="Visits" />
<ChartHistogramSeries Value="v => v.Seconds" Name="Visits" />
<ChartReferenceLine Argument="(2.5)" Label="Good: 2.5 s" />
</Chart>
{
private record PageVisit(double Seconds);
// Sample data: a skewed spread around 1.6 seconds, as page timings are.
private readonly PageVisit[] _visits = Visits(600, seed: 9);
private static PageVisit[] Visits(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());
return new PageVisit(Math.Round(1.6 * Math.Exp(0.45 * normal), 2));
})];
}
}Add this example to a page with the izzy CLI:
izzy add component ChartHistogramSeries --at <file>:<line>By default the bins are about as many as Sturges' rule gives for the number of values, at a round width on round edges. Bins sets them: ChartBins.Count(20) for at most 20, or ChartBins.Width(0.25) for a quarter second each. The width changes the picture, so try a few.
A ChartReferenceLine with an Argument marks a value on the scale, here Google's 2.5-second mark for a good load.
The last bin takes in the largest value, and an empty bin counts zero. Dates bin by a TimeSpan, such as ChartBins.Width(TimeSpan.FromDays(7)).
Split by a group
SeriesBy splits the counts by a group, here phones and desktops, on one set of bins. A lower Opacity lets each group's bars show through the other's.
Static
Preview
- Desktop
- Mobile
| Largest Contentful Paint (seconds) | Desktop | Mobile |
|---|---|---|
| 0.0 – 0.5 | 2 | 0 |
| 0.5 – 1.0 | 77 | 7 |
| 1.0 – 1.5 | 125 | 47 |
| 1.5 – 2.0 | 70 | 53 |
| 2.0 – 2.5 | 22 | 64 |
| 2.5 – 3.0 | 14 | 46 |
| 3.0 – 3.5 | 5 | 27 |
| 3.5 – 4.0 | 2 | 16 |
| 4.0 – 4.5 | 2 | 8 |
| 4.5 – 5.0 | 1 | 4 |
| 5.0 – 5.5 | 0 | 3 |
| 5.5 – 6.0 | 0 | 2 |
| 6.0 – 6.5 | 0 | 1 |
| 6.5 – 7.0 | 0 | 0 |
| 7.0 – 7.5 | 0 | 2 |
Code
@* The same page's load times on phones and on desktops: one set of bins, each device's bars
see-through so the two spreads show where they overlap. *@
<Chart Items="_visits" Title="Product page load time by device, March 9">
<ChartArgumentAxis Title="Largest Contentful Paint (seconds)" />
<ChartValueAxis Title="Visits" />
<ChartHistogramSeries Value="v => v.Seconds" SeriesBy="v => v.Device" Bins="ChartBins.Width(0.5)" Opacity="0.55" />
</Chart>
{
private record PageVisit(string Device, double Seconds);
// Sample data: desktops load in about 1.3 seconds, phones in about 2.2, both skewed.
private readonly PageVisit[] _visits = [.. Visits("Desktop", 1.3, 320, seed: 4), .. Visits("Mobile", 2.2, 280, seed: 5)];
private static IEnumerable<PageVisit> Visits(string device, double median, 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());
return new PageVisit(device, Math.Round(median * Math.Exp(0.4 * normal), 2));
}).ToList();
}
}With the chart's Stacking="ChartStacking.Normal", the groups stack instead, so each bar's height is the bin's total.
A histogram's chart holds only histogram series, upright, and doesn't zoom.
Details
The bars touch, the axis along the bottom is the values' own scale with the bins' edges marked, and the value axis counts from zero. Bins sets how they're cut. The chart takes no Argument. SeriesBy splits the counts by a group, on one set of bins: stacked with the chart's Stacking, or overlaid with a lower Opacity. A histogram's chart holds only histogram series; mark a value on its scale with a ChartReferenceLine's Argument, such as a target time.
Mode support
| Feature | Static | Interactive |
|---|---|---|
| Values cut into round bins: by Sturges' rule, a most count, or a width | Yes | Yes |
| Bars that touch, on an axis that marks the bins' edges | Yes | Yes |
| Numbers or dates, the last bin taking in the largest value | Yes | Yes |
| Split by a group on one set of bins, overlaid or stacked | Yes | Yes |
| Reference lines at a value on the scale, such as a target | Yes | Yes |
| Each bin read "2 – 2.5: 96" in tooltips and the table | Yes | Yes |
| A table of the counts in a "Show data" disclosure | 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 |
|---|---|---|
ValueThe value each item is counted by, such as o => o.DeliveryDays: a number or a date, or null to leave the item out. | Expression<Func<TItem, object?>> | Required |
BinsHow the values are cut into bins: Auto (the default), Count or Width. | ChartBins? | |
OpacityHow solid the bars are, from 0 to 1. | double? | computed |
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 |