Skip to content
IzzyBlazor

Enter all results ↑ ↓ move Esc close

Scatter chart

Since 0.1.0-alpha.22
Shows how two measures relate, a marker for each item.

Use 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

Load time against bounce rate, by page and device
  • Desktop
  • Desktop trend
  • Mobile
  • Mobile trend
Arrow keys move between values; Escape hides the tooltip.

Code

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

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

bash
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

What works in each mode, Scatter chart
FeatureStaticInteractive
Two measures on number or date scalesYesYes
Groups split into series by a value, each with its own marker shapeYesYes
Drawn on the server, as wide as its container, with labels that thin out as it narrowsYesYes
A table of the values behind a "Show data" buttonYesYes
Tooltips on hover and from the keyboardYesYes
Legend items that hide and show a seriesYesYes

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

ChartScatterSeries parameters
PropTypeDefault
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).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…