Skip to content
IzzyBlazor

Enter all results ↑ ↓ move Esc close

Heatmap

Since 0.1.0-alpha.22
Shows where values run high or low across two dimensions, such as the busiest hours of the week.

Use a heatmap to spot patterns across two dimensions, such as the busiest hours of the week. It shows where values run high or low, not exact amounts. When the numbers matter, show them in the cells or use a bar chart.

Values across two dimensions

Give HeatmapChart the Items, each one's Column, Row and Value, and a Title, here a shop's orders by hour.

Static

Preview

Orders by hour, last 4 weeks
  • 0 to 10
  • 10 to 20
  • 20 to 30
  • 30 to 40
  • 40 to 50
  • 50 to 60
Arrow keys move between values; Escape hides the tooltip.

Code

Usage.razor
@* A shop's online orders over the last four weeks, by weekday and hour. *@
<HeatmapChart Items="_orders" Column="o => o.Hour" Row="o => o.Day" Value="o => o.Orders"
              ColumnFormat="h tt" Title="Orders by hour, last 4 weeks" />

@code {
    private record HourlyOrders(string Day, TimeOnly Hour, int Orders);

    private static readonly string[] Days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];

    // Orders from 8 AM to 7 PM, a row per day.
    private static readonly int[][] Counts =
    [
        [12, 18, 26, 31, 38, 44, 35, 29, 27, 33, 40, 36],
        [14, 20, 27, 34, 41, 46, 37, 31, 28, 35, 42, 39],
        [13, 21, 29, 35, 43, 49, 39, 33, 30, 36, 44, 41],
        [15, 22, 30, 36, 42, 48, 38, 32, 31, 38, 47, 45],
        [16, 23, 28, 33, 39, 41, 34, 30, 33, 41, 52, 55],
        [9, 14, 22, 30, 37, 40, 42, 44, 43, 46, 49, 47],
        [6, 10, 17, 25, 31, 35, 38, 40, 39, 41, 38, 30],
    ];

    private readonly HourlyOrders[] _orders =
        [.. Days.SelectMany((day, d) => Counts[d].Select((n, h) => new HourlyOrders(day, new TimeOnly(8 + h, 0), n)))];
}

Add this example to a page with the izzy CLI:

bash
izzy add component HeatmapChart --at <file>:<line>

Columns and rows keep the order the items first name them in, the first row at the top. ColumnFormat formats the column names, here hours as "8 AM".

The values fall into about five classes between round bounds, here six of 10 orders each, shaded light to dark. The legend above the grid is that scale.

The values show in the cells while every one fits. At narrower widths they're left out, and pointing at a cell shows its tooltip instead.

Diverging colors

For values on either side of a meaningful middle, such as each month's temperature against the normal, set Palette to ChartPalette.Diverging with a color for each side. The scale turns gray at Midpoint (0 by default).

Static

Preview

Temperature against normal, 2025 (°C)
  • −4.0 to −2.0
  • −2.0 to 0.0
  • 0.0 to +2.0
  • +2.0 to +4.0
Arrow keys move between values; Escape hides the tooltip.

Code

Diverging.razor
@* How far each month's average temperature was from the city's 1991–2020 normal, in °C. *@
<HeatmapChart Items="_months" Column="m => m.Month" Row="m => m.City" Value="m => m.Difference"
              Palette="ChartPalette.Diverging(Color.Primary, Color.Danger)"
              ValueFormat="+0.0;−0.0;0.0" Legend="ChartLegend.End"
              Title="Temperature against normal, 2025 (°C)" />

@code {
    private record CityMonth(string City, string Month, double Difference);

    private static readonly string[] Months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

    private static readonly (string City, double[] Differences)[] Cities =
    [
        ("London", [0.8, 1.2, 1.9, 2.4, 1.1, 1.8, 2.6, 0.9, -0.3, 0.7, 1.4, 0.2]),
        ("Madrid", [1.1, 0.4, -0.8, 0.6, 2.3, 3.1, 2.8, 3.4, 1.6, 0.9, 0.5, -0.2]),
        ("Chicago", [-2.6, -1.4, 1.8, 0.4, -0.9, 1.2, 1.6, 0.8, 2.1, 1.9, -0.6, -1.8]),
        ("Tokyo", [0.3, -0.6, 1.4, 1.8, 0.9, 2.2, 2.9, 3.3, 2.6, 1.7, 0.8, 0.4]),
        ("Sydney", [1.2, 0.9, 1.6, 0.4, -0.7, 0.3, 0.6, 1.1, 1.8, 2.0, 1.3, 2.4]),
    ];

    private readonly CityMonth[] _months =
        [.. Cities.SelectMany(c => c.Differences.Select((d, m) => new CityMonth(c.City, Months[m], d)))];
}

The scale reaches as far on both sides, so colors of the same strength mean the same distance from the middle. Steps sets about how many classes there are (5 by default); here the bounds round to four classes of 2°C, two on each side.

Legend="ChartLegend.End" stands the scale upright beside the grid, with the high end at the top.

Named levels

When the values have levels with names of their own, such as a support team's "Quiet" to "Overloaded", give each a HeatmapRange with its From, To, Color and Label. The legend names each level with its bounds.

Static

Preview

Support queue, tickets waiting
  • Quiet 0 to 10
  • Steady 10 to 25
  • Busy 25 to 40
  • Overloaded 40 to 100
Arrow keys move between values; Escape hides the tooltip.

Code

Ranges.razor
@* Tickets waiting in a support queue at the top of each hour, with the team's own levels. *@
<HeatmapChart Items="_queue" Column="q => q.Hour" Row="q => q.Day" Value="q => q.Waiting"
              ColumnFormat="h tt" Title="Support queue, tickets waiting">
    <HeatmapRange From="0" To="10" Color="Quiet" Label="Quiet" />
    <HeatmapRange From="10" To="25" Color="Steady" Label="Steady" />
    <HeatmapRange From="25" To="40" Color="Busy" Label="Busy" />
    <HeatmapRange From="40" To="100" Color="Overloaded" Label="Overloaded" />
</HeatmapChart>

@code {
    // Light to dark for the levels; in dark mode, dark to light.
    private static readonly Color Quiet = Color.Of("light-dark(#dbeafe, #1e3a5f)");
    private static readonly Color Steady = Color.Of("light-dark(#93c5fd, #2f5f9e)");
    private static readonly Color Busy = Color.Of("light-dark(#3b82f6, #5b93e6)");
    private static readonly Color Overloaded = Color.Of("light-dark(#1e40af, #a8c8ff)");

    private record QueueHour(string Day, TimeOnly Hour, int Waiting);

    private static readonly string[] Days = ["Mon", "Tue", "Wed", "Thu", "Fri"];

    // Tickets waiting from 8 AM to 5 PM, a row per weekday.
    private static readonly int[][] Waiting =
    [
        [34, 46, 41, 30, 22, 26, 24, 19, 14, 9],
        [21, 28, 26, 20, 15, 18, 17, 13, 10, 7],
        [18, 24, 22, 17, 13, 16, 15, 12, 9, 6],
        [17, 23, 21, 16, 12, 14, 14, 11, 8, 6],
        [15, 19, 18, 14, 11, 9, 8, 6, 4, 3],
    ];

    private readonly QueueHour[] _queue =
        [.. Days.SelectMany((day, d) => Waiting[d].Select((n, h) => new QueueHour(day, new TimeOnly(8 + h, 0), n)))];
}

Order the colors light to dark, with light-dark() for dark mode, where the strongest shade is the lightest. With IzzyBlazor's script, each legend key hides and shows the cells at its level.

Thousands of cells

A heatmap holds thousands of cells: here a site's visitors in each hour of each day of a year, 365 columns by 24 rows. Steps="0" blends the color continuously, with a gradient for the legend.

Static

Preview

Visitors by hour, 2025
Arrow keys move between values; Escape hides the tooltip.

Code

Year.razor
@* A site's visitors in each hour of each day of 2025: busy weekday mornings and evenings, quiet nights, a summer dip. *@
<HeatmapChart Items="_visits" Column="v => v.Day" Row="v => v.Hour" Value="v => v.Visitors"
              RowFormat="HH:mm" CellHeight="Length.Rem(0.75)" Steps="0" ValueFormat="N0"
              Title="Visitors by hour, 2025" />

@code {
    private record HourlyVisits(DateOnly Day, TimeOnly Hour, int Visitors);

    private readonly HourlyVisits[] _visits = Build();

    private static HourlyVisits[] Build()
    {
        var start = new DateOnly(2025, 1, 1);
        var visits = new List<HourlyVisits>();
        for (var d = 0; d < 365; d++)
        {
            var day = start.AddDays(d);
            var weekend = day.DayOfWeek is DayOfWeek.Saturday or DayOfWeek.Sunday;
            // Fewer visitors in the summer weeks and over the holidays.
            var season = 1 - 0.35 * Math.Exp(-Math.Pow((d - 215) / 22.0, 2)) - (d > 354 ? 0.4 : 0);
            for (var h = 0; h < 24; h++)
            {
                // A morning peak and an evening peak; weekends later and flatter.
                var shape = weekend
                    ? 0.15 + 0.6 * Math.Exp(-Math.Pow((h - 14) / 4.5, 2))
                    : 0.08 + Math.Exp(-Math.Pow((h - 10) / 2.5, 2)) + 0.7 * Math.Exp(-Math.Pow((h - 20) / 2.0, 2));
                var noise = 0.85 + 0.3 * ((d * 7919 + h * 104729) % 97) / 97.0;
                visits.Add(new HourlyVisits(day, new TimeOnly(h, 0), (int)(1200 * shape * season * noise)));
            }
        }

        return [.. visits];
    }
}

Along the bottom, the columns are named by month. When a row is shorter than a line of text (CellHeight), every second row name shows.

Cells narrower than 6px lose their gaps and corners, so the grid reads as one surface. The cells are too small for values, so point at one for its tooltip.

Details

Columns and rows keep the order the items first name them in, the first row at the top. A cell with no item, or a null value, is drawn as no data, never as a zero. Colors are classes: five even steps from round bounds, light to dark, by default (Steps, Min, Max), a diverging palette's two sides of Midpoint, your own HeatmapRange children, or a continuous blend (Steps 0). The legend is the scale.

Parts

Written inside HeatmapChart. The API page lists their parameters.

  • HeatmapRange: a class of values on a HeatmapChart<T>'s or CalendarHeatmap<T>'s scale, with its own color and name, in place of the chart's even steps: <HeatmapRange From="0" To="10" Color="Color.Of("#dbeafe")" Label="Quiet" />.
  • HeatmapTooltip<TItem>: a HeatmapChart<T>'s or CalendarHeatmap<T>'s tooltip content, in place of the cell's row, column and value: <HeatmapTooltip Context="c">@c.Row, @c.Column: @c.Text orders</HeatmapTooltip>.

Mode support

What works in each mode, Heatmap
FeatureStaticInteractive
Cells colored in even steps from round bounds, light to dark, or blended continuouslyYesYes
A diverging scale for values above and below a midpointYesYes
Named ranges with your own colorsYesYes
Values in the cells where they fit, in ink that reads on the shadeYesYes
Names along the bottom that thin out as the grid narrows, by month for datesYesYes
A legend that is the color scale, beside or above the gridYesYes
Legend keys that hide and show the cells in their classYesYes
A table of the values, rows by columns, in a "Show data" disclosureYesYes
Tooltips on hover and from the keyboard, cell by cellYesYes

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.

  • Legend keys that hide and show the cells in their class: waits for the script
  • Tooltips on hover and from the keyboard, cell by cell: waits for the script

Accessibility

  • The chart is a figure captioned by Title, or named by a heading on the page with TitledBy.
  • The grid is one image named by the caption. The legend lists the scale's classes.
  • "Show data" under the chart opens the same values as a table, rows by columns (DataTable).
  • With script, the grid is one Tab stop: the arrow keys move from cell to cell and say each one's row, column and value.

Keyboard navigation

On the grid

HeatmapChart keys, On the grid
Press this keyTo do this
Right or LeftMove to the next or previous cell in the row (reversed on right-to-left pages)
Down or UpMove to the cell below or above
Home or EndGo to the first or last cell in the row
Ctrl+Home or Ctrl+EndGo to the first or last cell in the grid
EscapeHide the tooltip

Parameters

HeatmapChart parameters
PropTypeDefault
RefreshHow often the chart reads its data again, at least a second, such as Refresh="TimeSpan.FromSeconds(30)".TimeSpan?
RefreshFromOn a static page with Refresh: a lighter page to fetch than this one, which renders the same chart with the same id.string?
ItemsThe items, one cell each: each names its column, its row and its value.IEnumerable<TItem>?Required
ColumnEach item's column, such as o => o.Hour: text, a number or a date.Expression<Func<TItem, object?>>Required
RowEach item's row, such as o => o.Day.Expression<Func<TItem, object?>>Required
ValueEach item's value, such as o => o.Orders: any number, or null for no data.Expression<Func<TItem, object?>>Required
TitleThe chart's title, such as "Orders by hour", shown above it as its caption.string?
HideTitleHides the title, which still names the chart for screen readers.boolfalse
DownloadShows a button across from the title that saves the chart as a PNG, named after its title, in the color scheme on screen.boolfalse
TitleAlignWhere the title sits: at the start by default (the left, in a left-to-right page); ChartAlign.Center or ChartAlign.End.ChartAlignChartAlign.Start
TitledByThe id of a heading already on the page that titles the chart, such as a card's, in place of Title: the chart takes its name from it and shows no title of its own.string?
ValueFormatA .NET format string for the values, such as N0 or P0: in the cells, the legend, the tooltips and the table.string?
ColumnFormatA .NET format string for the column names, such as htt for hours or MMM d for dates.string?
RowFormatA .NET format string for the row names.string?
PaletteThe colors: Shades of the primary color by default, light to dark for low to high; Shades of another color; Diverging for values above and below Midpoint, such as change from last year; or your own ramp with Of, one class per color.ChartPalette?
StepsHow many classes the values fall into, each a shade: 5 by default, 2 to 9.int5
MidpointThe value a Diverging scale turns at, gray in the middle: 0 by default; a target or an average otherwise.double?
MinThe scale's low end, so heatmaps side by side share a scale.double?
MaxThe scale's high end.double?
LabelsThe values in the cells: with ChartLabels.Auto (the default) when every value fits its cell, coming and going with the width; ChartLabels.Inside always; ChartLabels.None never (the tooltip and "Show data" still give them).ChartLabelsChartLabels.Auto
CellHeightEach row's height: 2rem by default.Length?
LegendWhere the legend, the color scale, goes: above the grid by default (ChartLegend.Auto or ChartLegend.Top), ChartLegend.Bottom, or upright beside it with ChartLegend.Start or ChartLegend.End (above it under 30rem); ChartLegend.None leaves it out.ChartLegendChartLegend.Auto
LegendAlignThe legend's place along its edge: the start by default, the center or the end.ChartAlign?
TooltipThe tooltip for the cell under the pointer or the keyboard (with script), beside the cell.bool?
DataTableThe values as a table, rows by columns: by default behind a "Show data" button that opens it over the chart; ChartDataTable.Collapsed puts it in a disclosure under the chart.ChartDataTableChartDataTable.Popover
ChildContentHeatmapRanges, your own classes, and a HeatmapTooltip<T>.RenderFragment?
OnRefreshOn an interactive page with Refresh: raised at each interval, to load new data.EventCallback

See also

  • Chart: draws a chart on the server from a list of items, with axes, value labels, reference lines, trends and a table of the values, for every chart type.
  • CalendarHeatmap: shows a year of daily activity at a glance, such as a contributions graph, with busy days darker.

Connection lost

Rejoining the server…