DeepWorks Studios Blazor Component Library

Demo user Administrator ยท Blazor Server Library 20261206222504-6e8ff32.dirty

DwsChartHeatmap

Shows a matrix of values as a grid of colored cells: the higher the value, the further along the color scale its cell is. The grid fills its container on any screen and keeps its labels readable, the colors are theme colors, and hovering, focusing or tapping a cell shows its detail. The arrow keys move between the cells.

API Reference

Basic

Only ChartData is needed: column labels plus one row of values per row label. The scale runs from the lowest to the highest value, in shades of the theme's Primary color, and the legend below the grid explains it.

Visitors per hour
08
09
10
11
12
13
14
15
16
17
18
19
Mon
Tue
Wed
Thu
Fri
Sat
Sun
Show Code
HeatmapChart.razor
<DwsChartHeatmap Name='HeatmapChartDemo_Basic' ChartData='@_visits' Title='Visitors per hour' />
HeatmapChart.razor.cs
// Visitors of a shop per weekday and hour.
private readonly DwsChartHeatmapData _visits = new DwsChartHeatmapData(["08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"])
    .AddRow("Mon", 12, 38, 64, 71, 58, 44, 52, 66, 61, 43, 25, 14)
    .AddRow("Tue", 15, 41, 70, 78, 62, 47, 55, 72, 64, 45, 27, 16)
    .AddRow("Wed", 14, 40, 68, 80, 65, 49, 57, 70, 63, 46, 26, 15)
    .AddRow("Thu", 13, 39, 66, 75, 60, 45, 58, 74, 67, 48, 29, 17)
    .AddRow("Fri", 11, 33, 55, 61, 50, 38, 42, 47, 40, 28, 18, 10)
    .AddRow("Sat", 4, 8, 15, 22, 27, 29, 26, 21, 17, 12, 9, 6)
    .AddRow("Sun", 2, 5, 9, 14, 19, 21, 20, 16, 13, 10, 7, 4);

Visits per weekday and hour

A week of web shop visits, 24 hours as columns and the weekdays as rows - the hour-of-day pattern of an analytics page. Wide, every hour is labelled; on a phone every 2nd, 3rd or 6th, whatever fits at the label size; where the 24 cells do not fit, the grid scrolls sideways inside the chart with the weekdays pinned. ColorSteps 5 sorts the hours into five easily told levels. IsLoading shows a spinner instead of the grid while the data loads; Caption says what the grid shows.

00
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Mon
Tue
Wed
Thu
Fri
Sat
Sun
  • 0 to 5.2
  • 5.2 to 10.4
  • 10.4 to 15.6
  • 15.6 to 20.8
  • 20.8 to 26

Visits per hour, last week.

Show Code
HeatmapChart.razor
<DwsSwitch Name='HeatmapChartDemo_DenseLoading' @bind-Value='_denseLoading' Label='IsLoading' Class='mb-2' />
<DwsChartHeatmap Name='HeatmapChartDemo_Dense' ChartData='@_hours' IsLoading='@_denseLoading' Colors='@_green' ColorSteps='5' Min='0'
                 Caption='Visits per hour, last week.' />
HeatmapChart.razor.cs
private bool _denseLoading;
private readonly DwsColor[] _green = [DwsColor.Success];
private readonly DwsChartHeatmapData _hours = BuildHours();

// Visits per hour (columns) and weekday (rows): a daytime curve, lower at the weekend.
private static DwsChartHeatmapData BuildHours()
{
    string[] days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
    DwsChartHeatmapData data = new([.. Enumerable.Range(0, 24).Select(hour => $"{hour:00}")]);

    for (int day = 0; day < days.Length; day++)
    {
        int d = day;
        data.AddRow(days[d], [.. Enumerable.Range(0, 24).Select(hour => (double?)Math.Round(Math.Max(0, Math.Sin((hour - 6) / 24.0 * Math.PI * 2)) * (d >= 5 ? 14 : 22) + (hour * 7 + d * 3) % 5))]);
    }

    return data;
}

Missing values

A null value draws an empty cell, and its tooltip says that there is no value - here the hours a humidity sensor was offline.

06:00
09:00
12:00
15:00
18:00
21:00
Mon
Tue
Wed
Thu
Fri
Show Code
HeatmapChart.razor
<DwsChartHeatmap Name='HeatmapChartDemo_Missing' ChartData='@_humidity' ValueFormat="0'%'" ShowValues='true' />
HeatmapChart.razor.cs
// Relative humidity in percent per day and time; null where the sensor was offline.
private readonly DwsChartHeatmapData _humidity = new DwsChartHeatmapData(["06:00", "09:00", "12:00", "15:00", "18:00", "21:00"])
    .AddRow("Mon", 82, 71, 58, 52, 60, 74)
    .AddRow("Tue", 79, 68, null, null, 57, 70)
    .AddRow("Wed", 91, 88, 80, 77, 83, 90)
    .AddRow("Thu", 75, 62, 49, 44, null, 66)
    .AddRow("Fri", 70, 59, 47, 41, 50, 63);

Status mode: a week of hourly health checks

Statuses lists categories (key, label, theme color); rows added with AddStatusRow carry one status key per column. Cells take their status' color, the legend lists the statuses, and the tooltip names them. 168 hourly columns: the chart frame measures the width and shows only as many column labels as fit (here one per day) - no blank labels in the data. On a phone the grid scrolls sideways with the row labels pinned, a long row label is cut off (its full text is in the tooltip), and a tap pins a cell's tooltip until a tap elsewhere or Escape.

01.12 00:00
01.12 01:00
01.12 02:00
01.12 03:00
01.12 04:00
01.12 05:00
01.12 06:00
01.12 07:00
01.12 08:00
01.12 09:00
01.12 10:00
01.12 11:00
01.12 12:00
01.12 13:00
01.12 14:00
01.12 15:00
01.12 16:00
01.12 17:00
01.12 18:00
01.12 19:00
01.12 20:00
01.12 21:00
01.12 22:00
01.12 23:00
02.12 00:00
02.12 01:00
02.12 02:00
02.12 03:00
02.12 04:00
02.12 05:00
02.12 06:00
02.12 07:00
02.12 08:00
02.12 09:00
02.12 10:00
02.12 11:00
02.12 12:00
02.12 13:00
02.12 14:00
02.12 15:00
02.12 16:00
02.12 17:00
02.12 18:00
02.12 19:00
02.12 20:00
02.12 21:00
02.12 22:00
02.12 23:00
03.12 00:00
03.12 01:00
03.12 02:00
03.12 03:00
03.12 04:00
03.12 05:00
03.12 06:00
03.12 07:00
03.12 08:00
03.12 09:00
03.12 10:00
03.12 11:00
03.12 12:00
03.12 13:00
03.12 14:00
03.12 15:00
03.12 16:00
03.12 17:00
03.12 18:00
03.12 19:00
03.12 20:00
03.12 21:00
03.12 22:00
03.12 23:00
04.12 00:00
04.12 01:00
04.12 02:00
04.12 03:00
04.12 04:00
04.12 05:00
04.12 06:00
04.12 07:00
04.12 08:00
04.12 09:00
04.12 10:00
04.12 11:00
04.12 12:00
04.12 13:00
04.12 14:00
04.12 15:00
04.12 16:00
04.12 17:00
04.12 18:00
04.12 19:00
04.12 20:00
04.12 21:00
04.12 22:00
04.12 23:00
05.12 00:00
05.12 01:00
05.12 02:00
05.12 03:00
05.12 04:00
05.12 05:00
05.12 06:00
05.12 07:00
05.12 08:00
05.12 09:00
05.12 10:00
05.12 11:00
05.12 12:00
05.12 13:00
05.12 14:00
05.12 15:00
05.12 16:00
05.12 17:00
05.12 18:00
05.12 19:00
05.12 20:00
05.12 21:00
05.12 22:00
05.12 23:00
06.12 00:00
06.12 01:00
06.12 02:00
06.12 03:00
06.12 04:00
06.12 05:00
06.12 06:00
06.12 07:00
06.12 08:00
06.12 09:00
06.12 10:00
06.12 11:00
06.12 12:00
06.12 13:00
06.12 14:00
06.12 15:00
06.12 16:00
06.12 17:00
06.12 18:00
06.12 19:00
06.12 20:00
06.12 21:00
06.12 22:00
06.12 23:00
07.12 00:00
07.12 01:00
07.12 02:00
07.12 03:00
07.12 04:00
07.12 05:00
07.12 06:00
07.12 07:00
07.12 08:00
07.12 09:00
07.12 10:00
07.12 11:00
07.12 12:00
07.12 13:00
07.12 14:00
07.12 15:00
07.12 16:00
07.12 17:00
07.12 18:00
07.12 19:00
07.12 20:00
07.12 21:00
07.12 22:00
07.12 23:00
Database
Mail delivery
Payment provider API
Backups
  • Healthy
  • Degraded
  • Down

Worst check result per hour, last 7 days.

Show Code
HeatmapChart.razor
<DwsChartHeatmap Name='HeatmapChartDemo_Status' ChartData='@_health' Statuses='@_healthStatuses' CellGap='1' CellMinHeight='24'
                 ColumnLabelsAtBottom='true' Caption='Worst check result per hour, last 7 days.' />
HeatmapChart.razor.cs
private static readonly IReadOnlyList<DwsChartHeatmapStatus> _healthStatuses =
[
    new("ok", "Healthy", DwsColor.Success),
    new("warn", "Degraded", DwsColor.Warning),
    new("down", "Down", DwsColor.Error),
];

// 168 columns, one per hour ("dd.MM HH:00"); the heatmap shows as many labels as fit. A null key is an hour without a check.
private static readonly string[] Week = [.. Enumerable.Range(0, 168).Select(hour => $"{1 + hour / 24:00}.12 {hour % 24:00}:00")];

private readonly DwsChartHeatmapData _health = new DwsChartHeatmapData(Week)
    .AddStatusRow("Database", [.. Week.Select((_, i) => i is >= 50 and < 53 ? "down" : i % 37 == 5 ? "warn" : "ok")])
    .AddStatusRow("Mail delivery", [.. Week.Select((_, i) => i % 29 == 3 ? "warn" : "ok")])
    .AddStatusRow("Payment provider API", [.. Week.Select((_, i) => i < 4 ? null : i == 120 ? "down" : "ok")])
    .AddStatusRow("Backups", [.. Week.Select((_, i) => i % 24 == 2 ? "ok" : null)]);

Theme colors

Colors lists the theme colors (DwsColor) the scale runs through, from low to high, so the heatmap follows the active theme. One color runs from a pale tint of it to the full color.

Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
Oslo
Berlin
Madrid
Rome
Cairo
Sydney
Show Code
HeatmapChart.razor
<div class='d-flex flex-wrap gap-2 mb-3'>
    @foreach ((string label, DwsColor[] colors) in _palettes)
    {
        <DwsButton Name='@($"HeatmapChartDemo_Palette_{label.Replace(" ", string.Empty)}")'
                   Appearance='@(_palette == colors ? DwsAppearance.Filled : DwsAppearance.Outline)'
                   ButtonSize='DwsSize.Small'
                   OnClick='() => _palette = colors'>@label</DwsButton>
    }
</div>
<DwsChartHeatmap Name='HeatmapChartDemo_Colors' ChartData='@_temperatures' Colors='@_palette' ValueFormat='0 °C' />
HeatmapChart.razor.cs
// Average temperature per month in °C.
private readonly DwsChartHeatmapData _temperatures = new DwsChartHeatmapData(["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"])
    .AddRow("Oslo", -4, -4, 0, 5, 11, 15, 17, 16, 11, 6, 1, -3)
    .AddRow("Berlin", 1, 2, 5, 10, 15, 18, 20, 20, 15, 10, 5, 2)
    .AddRow("Madrid", 6, 8, 11, 13, 17, 23, 26, 26, 21, 15, 10, 7)
    .AddRow("Rome", 8, 9, 11, 14, 18, 22, 25, 25, 22, 17, 12, 9)
    .AddRow("Cairo", 14, 15, 18, 22, 25, 28, 29, 29, 27, 24, 19, 16)
    .AddRow("Sydney", 23, 23, 22, 19, 16, 14, 13, 14, 16, 18, 20, 22);

private readonly DwsColor[] _coldToHot = [DwsColor.Link, DwsColor.Warning, DwsColor.Error];

private static readonly DwsColor[] PrimaryOnly = [DwsColor.Primary];

private readonly (string Label, DwsColor[] Colors)[] _palettes;
private DwsColor[] _palette;

public HeatmapChart()
{
    _palettes =
    [
        ("Primary", PrimaryOnly),
        ("Link to Error", _coldToHot),
        ("Success to Error", [DwsColor.Success, DwsColor.Warning, DwsColor.Error]),
    ];

    _palette = _coldToHot;
}

A fixed scale

Min and Max fix the ends of the scale instead of taking them from the data, so a humidity of 100% always takes the high end of the scale, whatever this week's values are; values outside take the end colors.

06:00
09:00
12:00
15:00
18:00
21:00
Mon
Tue
Wed
Thu
Fri
Show Code
HeatmapChart.razor
<DwsChartHeatmap Name='HeatmapChartDemo_FixedScale' ChartData='@_humidity' Min='0' Max='100' ValueFormat="0'%'" ShowValues='true' />
HeatmapChart.razor.cs
// Relative humidity in percent per day and time; null where the sensor was offline.
private readonly DwsChartHeatmapData _humidity = new DwsChartHeatmapData(["06:00", "09:00", "12:00", "15:00", "18:00", "21:00"])
    .AddRow("Mon", 82, 71, 58, 52, 60, 74)
    .AddRow("Tue", 79, 68, null, null, 57, 70)
    .AddRow("Wed", 91, 88, 80, 77, 83, 90)
    .AddRow("Thu", 75, 62, 49, 44, null, 66)
    .AddRow("Fri", 70, 59, 47, 41, 50, 63);

Values in the cells

ShowValues writes each value into its cell, formatted with ValueFormat in the current culture, in black or white, whichever reads better on the cell's color. On cells of a middle color, where neither stands out much, ValueBackdrop (on by default) puts a soft light or dark backdrop behind the value; switch it off to compare. The cells then keep a width their values fit in, and on a narrow screen the grid scrolls sideways with its row labels pinned.

Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
Oslo
Berlin
Madrid
Rome
Cairo
Sydney
Show Code
HeatmapChart.razor
<DwsSwitch Name='HeatmapChartDemo_ValueBackdrop' @bind-Value='_valueBackdrop' Label='ValueBackdrop' Class='mb-3' />
<DwsChartHeatmap Name='HeatmapChartDemo_Values' ChartData='@_temperatures' ShowValues='true' ValueFormat='0°'
                 Colors='@_coldToHot' WithLegend='false' ValueBackdrop='@_valueBackdrop' />
HeatmapChart.razor.cs
// Average temperature per month in °C.
private readonly DwsChartHeatmapData _temperatures = new DwsChartHeatmapData(["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"])
    .AddRow("Oslo", -4, -4, 0, 5, 11, 15, 17, 16, 11, 6, 1, -3)
    .AddRow("Berlin", 1, 2, 5, 10, 15, 18, 20, 20, 15, 10, 5, 2)
    .AddRow("Madrid", 6, 8, 11, 13, 17, 23, 26, 26, 21, 15, 10, 7)
    .AddRow("Rome", 8, 9, 11, 14, 18, 22, 25, 25, 22, 17, 12, 9)
    .AddRow("Cairo", 14, 15, 18, 22, 25, 28, 29, 29, 27, 24, 19, 16)
    .AddRow("Sydney", 23, 23, 22, 19, 16, 14, 13, 14, 16, 18, 20, 22);

private readonly DwsColor[] _coldToHot = [DwsColor.Link, DwsColor.Warning, DwsColor.Error];

Cell template

CellTemplate replaces a cell's content and gets the same cell. The cell keeps its color, tooltip and accessible name; here a dot marks the busiest day of every week.

Mon
Tue
Wed
Thu
Fri
Sat
Sun
  • 0 to 2
  • 2 to 4
  • 4 to 6
  • 6 to 8
  • 8 to 10
Show Code
HeatmapChart.razor
<DwsChartHeatmap Name='HeatmapChartDemo_CellTemplateChart' ChartData='@_contributions' ShowColumnLabels='false'
                 Colors='@_green' ColorSteps='5' Min='0' CellGap='3' CellMinHeight='18'>
    <CellTemplate Context='cell'>
        @if (IsBusiestOfWeek(cell))
        {
            <span aria-hidden='true'>●</span>
        }
    </CellTemplate>
</DwsChartHeatmap>
HeatmapChart.razor.cs
private readonly DwsChartHeatmapData _contributions = BuildContributions();
private static readonly DateOnly ContributionsStart = new(2026, 3, 2);
private readonly DwsColor[] _green = [DwsColor.Success];

// Contributions per day over 26 weeks: rows are weekdays, columns weeks starting on ContributionsStart.
private static DwsChartHeatmapData BuildContributions()
{
    string[] days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
    DwsChartHeatmapData data = new(Enumerable.Range(1, 26).Select(week => $"W{week}"));

    for (int day = 0; day < 7; day++)
    {
        int weekday = day;
        data.AddRow(days[day], [.. Enumerable.Range(0, 26).Select(week => (double?)Contributions(weekday, week))]);
    }

    return data;
}

private static double Contributions(int day, int week)
{
    int seed = (day * 31 + week * 17 + day * week) % 13;
    return day >= 5 ? Math.Max(0, seed - 9) : Math.Max(0, seed - 2);
}

private static DateOnly DateOf(DwsChartHeatmapCell cell) => ContributionsStart.AddDays(cell.ColumnIndex * 7 + cell.RowIndex);

// The day of the cell's week with the most contributions (the first one on a tie), if it has any.
private bool IsBusiestOfWeek(DwsChartHeatmapCell cell)
{
    double? best = null;
    int bestRow = -1;

    for (int row = 0; row < _contributions.Rows.Count; row++)
    {
        double? value = _contributions.Rows[row].Values[cell.ColumnIndex];

        if (value > (best ?? 0))
        {
            best = value;
            bestRow = row;
        }
    }

    return bestRow == cell.RowIndex;
}

No data

Without rows or columns the heatmap shows NoDataText, or the localized default when it is not set (first example). EmptyContent replaces that text with content of your own (second example).

No data to display
No checks have run yet.
Show Code
HeatmapChart.razor
<!-- No rows or columns: the localized "No data to display" -->
<DwsChartHeatmap Name='HeatmapChartDemo_Empty' ChartData='null' />

<!-- Or content of your own -->
<DwsChartHeatmap Name='HeatmapChartDemo_EmptyContent' ChartData='null' Class='mt-3'>
    <EmptyContent>
        <span>No checks have run yet.</span>
    </EmptyContent>
</DwsChartHeatmap>

Width and height

Width, Height, MinWidth, MaxWidth, MinHeight and MaxHeight size the heatmap in pixels, caption and legend included; with a height the rows share what is left. Drag the corner of the box: this one is 300px high and keeps between 240px and 720px wide.

08
09
10
11
12
13
14
15
16
17
18
19
Mon
Tue
Wed
Thu
Fri
Sat
Sun
Show Code
HeatmapChart.razor
<div class='heatmap-demo-resizable'>
    <DwsChartHeatmap Name='HeatmapChartDemo_Size' ChartData='@_visits' Height='300' MinWidth='240' MaxWidth='720' />
</div>

<style>
    .heatmap-demo-resizable {
        resize: horizontal;
        overflow: auto;
        width: 100%;
        min-width: 240px;
        max-width: 100%;
        padding: 0.5rem;
        border: 1px dashed var(--secondary);
    }
</style>
HeatmapChart.razor.cs
// Visitors of a shop per weekday and hour.
private readonly DwsChartHeatmapData _visits = new DwsChartHeatmapData(["08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"])
    .AddRow("Mon", 12, 38, 64, 71, 58, 44, 52, 66, 61, 43, 25, 14)
    .AddRow("Tue", 15, 41, 70, 78, 62, 47, 55, 72, 64, 45, 27, 16)
    .AddRow("Wed", 14, 40, 68, 80, 65, 49, 57, 70, 63, 46, 26, 15)
    .AddRow("Thu", 13, 39, 66, 75, 60, 45, 58, 74, 67, 48, 29, 17)
    .AddRow("Fri", 11, 33, 55, 61, 50, 38, 42, 47, 40, 28, 18, 10)
    .AddRow("Sat", 4, 8, 15, 22, 27, 29, 26, 21, 17, 12, 9, 6)
    .AddRow("Sun", 2, 5, 9, 14, 19, 21, 20, 16, 13, 10, 7, 4);

Cell gap

CellGap sets the space between the cells in pixels; 0 draws one smooth surface.

Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
Oslo
Berlin
Madrid
Rome
Cairo
Sydney
Show Code
HeatmapChart.razor
<div class='d-flex flex-wrap gap-2 mb-3'>
    @foreach (int gap in _gapOptions)
    {
        <DwsButton Name='@($"HeatmapChartDemo_CellGap_{gap}")'
                   Appearance='@(_cellGap == gap ? DwsAppearance.Filled : DwsAppearance.Outline)'
                   ButtonSize='DwsSize.Small'
                   OnClick='() => _cellGap = gap'>CellGap @gap</DwsButton>
    }
</div>
<DwsChartHeatmap Name='HeatmapChartDemo_GapChart' ChartData='@_temperatures' Colors='@_coldToHot' ValueFormat='0 °C' CellGap='@_cellGap' />
HeatmapChart.razor.cs
// Average temperature per month in °C.
private readonly DwsChartHeatmapData _temperatures = new DwsChartHeatmapData(["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"])
    .AddRow("Oslo", -4, -4, 0, 5, 11, 15, 17, 16, 11, 6, 1, -3)
    .AddRow("Berlin", 1, 2, 5, 10, 15, 18, 20, 20, 15, 10, 5, 2)
    .AddRow("Madrid", 6, 8, 11, 13, 17, 23, 26, 26, 21, 15, 10, 7)
    .AddRow("Rome", 8, 9, 11, 14, 18, 22, 25, 25, 22, 17, 12, 9)
    .AddRow("Cairo", 14, 15, 18, 22, 25, 28, 29, 29, 27, 24, 19, 16)
    .AddRow("Sydney", 23, 23, 22, 19, 16, 14, 13, 14, 16, 18, 20, 22);

private readonly DwsColor[] _coldToHot = [DwsColor.Link, DwsColor.Warning, DwsColor.Error];

private readonly int[] _gapOptions = [0, 2, 4];
private int _cellGap = 2;

Vertical scrolling

A heatmap taller than MaxHeight scrolls, and its column labels stay on top: here MaxHeight limits the height of 24 hourly rows.

Mon
Tue
Wed
Thu
Fri
Sat
Sun
00:00
01:00
02:00
03:00
04:00
05:00
06:00
07:00
08:00
09:00
10:00
11:00
12:00
13:00
14:00
15:00
16:00
17:00
18:00
19:00
20:00
21:00
22:00
23:00
Show Code
HeatmapChart.razor
<DwsChartHeatmap Name='HeatmapChartDemo_MaxHeight' ChartData='@_hourly' MaxHeight='260' CellMinHeight='22' WithLegend='false' />
HeatmapChart.razor.cs
private readonly DwsChartHeatmapData _hourly = BuildHourly();

// Visitors per hour of the day (rows) and weekday (columns): a morning and an afternoon peak on workdays.
private static DwsChartHeatmapData BuildHourly()
{
    string[] days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
    DwsChartHeatmapData data = new(days);

    for (int hour = 0; hour < 24; hour++)
    {
        data.AddRow($"{hour:00}:00", [.. days.Select((_, day) => (double?)Visitors(day, hour))]);
    }

    return data;
}

private static double Visitors(int day, int hour)
{
    double workday = 80 * Math.Exp(-Math.Pow(hour - 10, 2) / 6) + 60 * Math.Exp(-Math.Pow(hour - 15, 2) / 5);
    double weekend = 45 * Math.Exp(-Math.Pow(hour - 13, 2) / 12);

    return Math.Round((day < 5 ? workday : weekend) + (day * 7 + hour * 3) % 6);
}

Horizontal scrolling

CellMinWidth keeps every cell at least 44px wide in a narrow box; the grid then scrolls sideways and the row labels stay on the left.

Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
Oslo
Berlin
Madrid
Rome
Cairo
Sydney
Show Code
HeatmapChart.razor
<div class='heatmap-demo-narrow'>
    <DwsChartHeatmap Name='HeatmapChartDemo_CellMinWidth' ChartData='@_temperatures' Colors='@_coldToHot' ValueFormat='0 °C'
                     CellMinWidth='44' WithLegend='false' />
</div>

<style>
    .heatmap-demo-narrow {
        width: 320px;
        max-width: 100%;
        padding: 0.5rem;
        border: 1px dashed var(--secondary);
    }
</style>
HeatmapChart.razor.cs
// Average temperature per month in °C.
private readonly DwsChartHeatmapData _temperatures = new DwsChartHeatmapData(["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"])
    .AddRow("Oslo", -4, -4, 0, 5, 11, 15, 17, 16, 11, 6, 1, -3)
    .AddRow("Berlin", 1, 2, 5, 10, 15, 18, 20, 20, 15, 10, 5, 2)
    .AddRow("Madrid", 6, 8, 11, 13, 17, 23, 26, 26, 21, 15, 10, 7)
    .AddRow("Rome", 8, 9, 11, 14, 18, 22, 25, 25, 22, 17, 12, 9)
    .AddRow("Cairo", 14, 15, 18, 22, 25, 28, 29, 29, 27, 24, 19, 16)
    .AddRow("Sydney", 23, 23, 22, 19, 16, 14, 13, 14, 16, 18, 20, 22);

private readonly DwsColor[] _coldToHot = [DwsColor.Link, DwsColor.Warning, DwsColor.Error];

Interface-Description

Name Typ Parameters Description
GetDataAsCsv string CultureInfo? culture The data the chart was given as CSV text (RFC 4180, CRLF, a header line): one row per mark in data order, the values as passed in. Null writes numbers the invariant way with commas between the cells; a culture writes them its way with its list separator. Text a spreadsheet would run as a formula gets an apostrophe in front.
ExportDataAsync Task string? fileName, CultureInfo? culture Downloads GetDataAsCsv() as a .csv file (UTF-8 with a byte order mark). Null names the file after the chart's title, else its Name.
SelectRangeAsync(int firstRow, int firstColumn, int lastRow, int lastColumn, bool additive = false) Task Selects the block of cells between these rows and columns (both ends included). Works without AllowBrushSelection too.
ClearSelectionAsync Task Clears the selection. The property SelectedCells returns the selected cells.
FocusAsync ValueTask bool containedInScrollableList Focuses the cell that takes part in the tab order: the top left one, or the one the user was on last. Does nothing while the heatmap is hidden, empty, disabled or in permission select mode.
Name Typ Default Description
ChartData DwsChartHeatmapData? null The matrix to draw: Columns (labels, left to right) and Rows (each with a Label, one double? per column and an optional Tag). AddRow(label, values...) chains rows. A null value, NaN or infinity draws an empty cell (the last two are logged as a warning); a row with more values than labels adds columns labelled with their number. Null, or no row or column, shows NoDataText.
Title string? null Caption above the heatmap, also its accessible name.
NoDataText string? null Text shown when there is nothing to draw. Null uses the localized "No data to display".
EmptyContent RenderFragment? null Shown instead of the grid when there is nothing to draw; null shows NoDataText.
IsLoading bool false The data is still loading: a spinner instead of the grid.
Caption string? null A sentence under the heatmap (what it shows, the source); the grid is described by it (aria-describedby).
Statuses IReadOnlyList<DwsChartHeatmapStatus>? null Status mode: categories (Key, Label, DwsColor Color). Rows with StatusKeys (AddStatusRow(label, keys...)) are colored by status instead of value; the legend lists the statuses, the tooltip and accessible name say them.
Width int? null Width in px. Never wider than the container unless MinWidth asks for more. Null fills the container.
Height int? null Height in px, caption and legend included; the rows share what is left and shrink to fit it, down to CellMinHeight (1.25rem by default here), before the grid scrolls. Null gives every row CellMinHeight.
MinWidth int? null Smallest width in px; the only size that may make the heatmap wider than its container.
MaxWidth int? null Largest width in px, and never more than the container.
MinHeight int? null Smallest height in px; the rows grow to fill it.
MaxHeight int? null Largest height in px; a taller grid scrolls with its column labels pinned.
CellMinWidth int? null Narrowest cell width in px. A container too narrow for all columns scrolls the grid sideways with its row labels pinned. Null lets the cells share the width (2.75rem minimum with ShowValues).
CellMinHeight int? null Smallest row height in px. Null uses 1.75rem, and 1.25rem with a Height, so the rows shrink to fit it before the grid scrolls.
CellGap int 2 Space between the cells in px. 0 draws one smooth surface with square cells.
Colors IReadOnlyList<DwsColor>? null Theme colors the scale runs through, lowest value first. One color runs from a pale tint of it to the full color; several blend evenly into each other (in the browser, so the heatmap follows the active theme). Null or empty uses Primary; Undefined entries are skipped.
ColorSteps int? null Splits the scale into this many equal steps of one color each; the legend then lists every step with its range. Null draws a smooth scale; less than 2 draws a smooth scale and more than 20 draws 20, both with a warning. A value on a step's lower bound belongs to that step.
Min double? null Value at the low end of the scale; lower values take the lowest color (all of them, when Min lies above all data). Null uses the lowest value in the data. Min above Max is swapped with a warning.
Max double? null Value at the high end of the scale; higher values take the highest color. Null uses the highest value in the data.
ShowRowLabels bool true Shows the row labels. Long ones are cut off with an ellipsis at 40% of the width; the tooltip and the accessible name keep the full label.
ShowColumnLabels bool true Shows the column labels. A column too narrow for its label shows it upright, read from the bottom up.
ColumnLabelsAtBottom bool false Puts the column labels below the grid instead of above it.
RowLabelsAtEnd bool false Puts the row labels after the cells (on the right) instead of before them.
ShowValues bool false Writes each value into its cell, in black or white, whichever reads better on the cell's color.
ValueBackdrop bool true With ShowValues: puts a soft backdrop behind a value on a cell of a middle color, white behind black text and black behind white text, where the text alone reaches only about 4.6:1. It fades out as the cell gets lighter or darker; cells with a clearly light or dark color get none. Needs a browser with relative colors (the same that pick black or white text).
ValueFormat string "#,0.##" .NET number format for values in the cells, the tooltip and the legend, in the current UI culture. An invalid format falls back to the default with a warning.
CellTemplate RenderFragment<DwsChartHeatmapCell>? null Content of a cell instead of its value. The cell keeps its color, tooltip and events, and its accessible name stays row, column and value, so the content is decoration for sighted users. Controls (buttons, inputs) do not belong in a cell: the grid handles the keys.
WithLegend bool true Shows the color scale: a gradient with the lowest, middle and highest value, or with ColorSteps one entry per step with its range. Hidden while the scale has no range: no value, and not both Min and Max.
LegendPosition DwsChartLegendPosition DwsChartLegendPosition.Bottom Bottom, Top, Right or Left of the grid. Right and Left run the scale upwards and move below the grid on screens narrower than 576px.
ShowTooltip bool true Shows the detail of the hovered or focused cell; on touch screens a tap shows it. Escape hides it until the next cell.
TooltipTemplate RenderFragment<DwsChartHeatmapCell>? null Content of the tooltip. Null shows the row and column label and the value.
HighlightOnHover bool true Highlights the row and column label of the hovered or focused cell and, while the pointer is on a legend step, fades every cell outside it (a pointer-only aid: each cell names its value).
AllowBrushSelection bool false Lets the user select cells: by dragging a rectangle over the grid with the mouse or a pen (every cell it touches; Ctrl / Cmd adds to the selection), or with the keyboard - Shift and an arrow key extend a block from the focused cell, Shift and Space add or remove the focused cell, Escape clears. Selected cells carry aria-selected. A finger dragged over the grid scrolls the page. Needs interactivity for the pointer.
Name Typ Description
OnCellClick EventCallback<DwsChartHeatmapCell> Raised when a cell is clicked, tapped or activated with Enter/Space; also for empty cells (Value null). Not raised while disabled or in permission select mode (a click then selects the heatmap).
OnCellHover EventCallback<DwsChartHeatmapCell?> Raised when the pointer or focus enters a cell, and with null when neither is on a cell any more: also when the heatmap stops reacting (disabled, permission select mode) or new data no longer has the cell.
OnRangeSelected EventCallback<DwsChartHeatmapRangeSelectedEventArgs> Raised when the selection changed: Cells (every selected cell, row by row), FirstRow, LastRow, FirstColumn, LastColumn (the block they lie in, null without a selection) and ByKeyboard.
Name Typ Default Description
Element ElementReference The associated web component. May be null if accessed before the component is rendered.
ComponentGuid Guid Unique identifier for the component.
TypeString string The name of the component type, obtained from reflection.
Authorized_RegisterEnabled bool false Indicates whether this component is enabled through a permission registry.
Authorized_RegisterSelected bool false Indicates whether this component is selected in permission selection mode.
GetInitializedState bool false Returns whether the component is initialized.
GetRenderModeState DwsRenderMode Returns the current render mode.
GetComponentState DwsComponentStateType Returns the current component state.
GetIsInteractiveState bool false Returns whether the component is interactive.
GetIsPrerenderingState bool false Returns whether the component is prerendering.
GetComponentLoadingState bool false Returns whether the component is loading.
IsFormBusy bool false Whether the DwsForm (or DwsFormBusyRegion) around the component is locked because its submit handler is running. The state itself is the cascaded FormBusyState (IDwsFormBusyState).
Name Typ Parameters Description
DebugInfo void Logs debug information about the component.
UpdateState void Updates the component's state and triggers StateHasChanged.
UpdateStateAsync Task Asynchronously updates the component's state and triggers StateHasChanged.
Dispose void Disposes the component and releases resources.
FocusAsync ValueTask bool containedInScrollableList Sets focus to the component's element.
Name Typ Default Description
Name string Required unique identifier for the component within its container.
Visible bool true Determines if the component is visible in the UI.
Disabled bool false Disables the form control, ensuring it doesn't participate in form submission.
ComponentNameSpace string The namespace for permission-based access control.
PermissionKey string? null A stable key that takes the place of Name in the generated permission namespace (Page.PermissionKey): the stored permission survives a rename, and components that share a key share one permission entry. Null: keyed by Name. Read once, when the component registers; an explicit ComponentNameSpace wins.
Class string Optional CSS class names.
Style string Optional in-line styles.
Tag object An optional user-defined object to store any additional data with the component.
BackReference DwsReference A reference to the enclosing component.
ID string The HTML ID attribute for the component.
AdditionalAttributes Dictionary<string, object> Additional HTML attributes for the component's root element.
IgnorePermissionChecks bool false Bypasses all permission checks for this component.
IgnorePermissionSelection bool false Ignore permission selection mode for this component.
IgnoreFormBusy bool false Takes the component out of the submit lock of the DwsForm (or DwsFormBusyRegion) around it: IsFormBusy stays false for it.
Name Typ Description
OnInitializedCallbackStarted EventCallback Callback when OnInitialized starts.
OnInitializedCallback EventCallback Callback during OnInitialized.
OnInitializedCallbackCompleted EventCallback Callback when OnInitialized completes.
OnInitializedAsyncCallbackStarted EventCallback Callback when OnInitializedAsync starts.
OnInitializedAsyncCallback EventCallback Callback during OnInitializedAsync.
OnInitializedAsyncCallbackCompleted EventCallback Callback when OnInitializedAsync completes.
OnIsComponentLoadingChanged EventCallback<bool> Callback when IsComponentLoading changes.
OnCurrentRenderModeChanged EventCallback<DwsRenderMode> Callback when CurrentRenderMode changes.
OnComponentStateChanged EventCallback<DwsComponentStateType> Callback when ComponentState changes.
An error has occurred. This app may no longer respond until reloaded.