Scatter chart
Since 0.1.0-alpha.22Use a scatter chart to see whether two measures move together, such as page load time and bounce rate. It shows clusters and outliers too. It doesn't show that one causes the other. With thousands of points, use a heatmap of counts.
Two measures against each other
To show how two measures relate across many items, use ChartScatterSeries, with one measure as the Argument and the other as the series' Value. Name both measures with each axis's Title, since nothing else says which is which.
Static
Preview
- Desktop
- Desktop trend
- Mobile
- Mobile trend
| Load time | Desktop | Desktop trend | Mobile | Mobile trend |
|---|---|---|---|---|
| 0.6 s | 21% | 21% | 24% | |
| 1.5 s | 27% | 29% | 31% | |
| 1.5 s | 31% | 27% | 31% | |
| 2.8 s | 35% | 38% | 42% | |
| 0.9 s | 18% | 23% | 26% | |
| 2.0 s | 30% | 29% | 35% | |
| 1.9 s | 24% | 29% | 34% | |
| 3.2 s | 38% | 48% | 45% | |
| 1.6 s | 31% | 27% | 32% | |
| 3.1 s | 37% | 50% | 44% | |
| 1.4 s | 18% | 26% | 30% | |
| 2.8 s | 35% | 43% | 42% | |
| 0.5 s | 24% | 20% | 23% | |
| 1.3 s | 25% | 29% | 29% | |
| 0.3 s | 23% | 19% | 21% | |
| 1.3 s | 25% | 25% | 29% | |
| 1.0 s | 25% | 23% | 27% | |
| 1.9 s | 29% | 28% | 34% | |
| 1.3 s | 24% | 25% | 29% | |
| 2.7 s | 35% | 43% | 41% | |
| 0.5 s | 16% | 20% | 23% | |
| 1.0 s | 23% | 33% | 27% | |
| 0.4 s | 24% | 19% | 22% | |
| 1.3 s | 25% | 31% | 29% | |
| 0.6 s | 12% | 21% | 24% | |
| 1.0 s | 23% | 22% | 27% | |
| 0.7 s | 28% | 21% | 24% | |
| 1.3 s | 25% | 29% | 29% | |
| 0.5 s | 14% | 20% | 23% | |
| 1.3 s | 25% | 36% | 29% | |
| 1.1 s | 30% | 24% | 28% | |
| 2.2 s | 31% | 41% | 37% | |
| 0.7 s | 18% | 21% | 24% | |
| 1.4 s | 26% | 26% | 30% | |
| 0.6 s | 25% | 21% | 24% | |
| 1.3 s | 25% | 25% | 29% | |
| 0.9 s | 30% | 23% | 26% | |
| 1.9 s | 29% | 38% | 34% | |
| 1.1 s | 32% | 24% | 28% | |
| 2.2 s | 31% | 30% | 37% | |
| 1.3 s | 21% | 25% | 29% | |
| 2.6 s | 34% | 33% | 40% | |
| 0.9 s | 16% | 23% | 26% | |
| 2.0 s | 30% | 30% | 35% | |
| 0.5 s | 23% | 20% | 23% | |
| 1.5 s | 27% | 25% | 31% | |
| 0.8 s | 17% | 22% | 25% | |
| 1.5 s | 27% | 38% | 31% | |
| 1.0 s | 25% | 23% | 27% | |
| 1.8 s | 29% | 31% | 34% | |
| 0.4 s | 26% | 19% | 22% | |
| 1.4 s | 26% | 36% | 30% | |
| 0.7 s | 18% | 21% | 24% | |
| 1.8 s | 29% | 35% | 34% | |
| 0.8 s | 20% | 22% | 25% | |
| 1.8 s | 29% | 34% | 34% | |
| 1.5 s | 27% | 27% | 31% | |
| 2.9 s | 36% | 47% | 43% | |
| 0.3 s | 13% | 19% | 21% | |
| 1.4 s | 26% | 35% | 30% | |
| 1.2 s | 18% | 25% | 29% | |
| 2.5 s | 33% | 47% | 39% | |
| 0.9 s | 23% | 23% | 26% | |
| 2.0 s | 30% | 43% | 35% | |
| 2.3 s | 29% | 32% | 38% | |
| 4.0 s | 43% | 55% | 52% | |
| 1.2 s | 19% | 25% | 29% | |
| 2.1 s | 31% | 32% | 36% | |
| 1.9 s | 28% | 29% | 34% | |
| 3.8 s | 42% | 55% | 50% | |
| 2.9 s | 36% | 36% | 43% | |
| 4.8 s | 48% | 63% | 59% | |
| 0.7 s | 23% | 21% | 24% | |
| 1.6 s | 27% | 36% | 32% | |
| 0.7 s | 21% | 21% | 24% | |
| 1.7 s | 28% | 29% | 33% | |
| 1.8 s | 24% | 29% | 34% | |
| 3.3 s | 38% | 38% | 46% | |
| 0.5 s | 14% | 20% | 23% | |
| 1.2 s | 25% | 27% | 29% | |
| 1.7 s | 27% | 28% | 33% | |
| 3.2 s | 38% | 47% | 45% | |
| 1.7 s | 25% | 28% | 33% | |
| 2.7 s | 35% | 48% | 41% | |
| 1.5 s | 34% | 27% | 31% | |
| 2.7 s | 35% | 40% | 41% | |
| 1.5 s | 33% | 27% | 31% | |
| 2.6 s | 34% | 33% | 40% | |
| 0.8 s | 28% | 22% | 25% | |
| 2.0 s | 30% | 39% | 35% | |
| 2.4 s | 40% | 33% | 39% | |
| 4.3 s | 45% | 45% | 54% | |
| 1.0 s | 26% | 23% | 27% | |
| 2.2 s | 31% | 35% | 37% | |
| 0.8 s | 24% | 22% | 25% | |
| 1.6 s | 27% | 30% | 32% | |
| 0.6 s | 26% | 21% | 24% | |
| 1.4 s | 26% | 40% | 30% | |
| 0.5 s | 17% | 20% | 23% | |
| 1.1 s | 24% | 25% | 28% |
Code
@* Each page's load time against its bounce rate, on desktop and on mobile, each with a straight
line of best fit: the slower pages lose more visitors, and pages are slower on mobile. *@
<Chart Items="_pages" Argument="p => p.LoadSeconds" Title="Load time against bounce rate, by page and device">
<ChartValueAxis Format="P0" Title="Bounce rate" />
<ChartArgumentAxis Format="0.0' s'" Title="Load time" />
<ChartScatterSeries Value="p => p.BounceRate" SeriesBy="p => p.Device" Trend="ChartTrend.Linear" />
<ChartTooltip>
<div class="ib-chart-tooltip-title">context.Item.Path</div>
<div>context.Item.Device, loads in context.Argument</div>
<div>context.Points.First(p => p.Text is not null).Text bounce</div>
</ChartTooltip>
</Chart>
{
private record PageStats(string Path, string Device, double LoadSeconds, double BounceRate);
private static readonly string[] Sections = ["docs", "blog", "products", "pricing", "guides", "changelog", "help", "customers"];
private readonly PageStats[] _pages = Pages();
// 50 pages, each on desktop and on mobile: bounce rate rises with load time, with some spread;
// on mobile pages load slower and bounce a little more.
private static PageStats[] Pages()
{
var random = new Random(42);
return Enumerable.Range(0, 50).SelectMany(i =>
{
var path = $"/{Sections[i % Sections.Length]}/page-{i / Sections.Length + 1}";
var weight = random.NextDouble() * random.NextDouble();
return new[] { ("Desktop", 0.5 + weight * 3.0, 0.0), ("Mobile", 1.2 + weight * 4.6, 0.06) }.Select(d =>
{
var load = Math.Round(d.Item2 + (random.NextDouble() - 0.5) * 0.4, 1);
var bounce = Math.Clamp(0.16 + d.Item3 + load * 0.07 + (random.NextDouble() - 0.5) * 0.16, 0.08, 0.92);
return new PageStats(path, d.Item1, load, Math.Round(bounce, 3));
});
}).ToArray();
}
}Add this example to a page with the izzy CLI:
izzy add component ChartScatterSeries --at <file>:<line>Both scales start where the values do rather than at zero.
SeriesBy splits a series into one per value of a property, here the device, each with its own color and marker shape. Trend="ChartTrend.Linear" draws each one's straight line of best fit.
The tooltip is for the point nearest the pointer, and the arrow keys move between points from left to right. Here a ChartTooltip names the page.
Mode support
| Feature | Static | Interactive |
|---|---|---|
| Two measures on number or date scales | Yes | Yes |
| Groups split into series by a value, each with its own marker shape | Yes | Yes |
| Drawn on the server, as wide as its container, with labels that thin out as it narrows | Yes | Yes |
| A table of the values behind a "Show data" button | Yes | Yes |
| Tooltips on hover and from the keyboard | Yes | Yes |
| Legend items that hide and show a series | 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
- Legend items that hide and show a series: waits for the script
Parameters
| Prop | Type | Default |
|---|---|---|
ValueThe value to draw, such as m => m.Revenue: any number, or null for none. | Expression<Func<TItem, object?>> | Required |
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 |