Skip to content
IzzyBlazor

Enter all results ↑ ↓ move Esc close

Treemap

Since 0.1.0-alpha.22
Shows which parts take the biggest share of a total, such as the largest lines in a budget.

Use a treemap to find the biggest parts of a large total, such as spending by department and line. It fits many parts in little space. People judge areas loosely, so for exact comparisons, use a bar chart.

Tiles in groups

Give TreemapChart the Items, with a Name and a Value for each, a Group to sort them under, and a Title.

Static

Preview

Cloud costs in October
Arrow keys move between tiles; Escape hides the tooltip.15 tiles in 5 groups, the largest App servers, $18,400

Code

Usage.razor
@* A software company's cloud bill for October, by service, grouped by what each service is for. *@
<TreemapChart Items="_costs"
              Name="c => c.Service"
              Value="c => c.Amount"
              Group="c => c.Category"
              ValueFormat="C0"
              Values
              Title="Cloud costs in October" />

@code {
    private record Cost(string Category, string Service, decimal Amount);

    private readonly Cost[] _costs =
    [
        new("Compute", "App servers", 18400),
        new("Compute", "Background jobs", 7200),
        new("Compute", "Build runners", 3100),
        new("Database", "Primary database", 12600),
        new("Database", "Read replicas", 6300),
        new("Database", "Cache", 2400),
        new("Storage", "Object storage", 5200),
        new("Storage", "Backups", 2900),
        new("Storage", "Block volumes", 1800),
        new("Network", "Data transfer", 6100),
        new("Network", "Load balancers", 1500),
        new("Network", "CDN", 1200),
        new("Monitoring", "Logs", 3800),
        new("Monitoring", "Metrics", 1400),
        new("Monitoring", "Tracing", 700),
    ];
}

Add this example to a page with the izzy CLI:

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

Values writes each tile's amount under its name, and a group's total beside its own.

A name shows only where it fits its tile: hover a tile for its value and shares, or Tab to the chart and move between tiles with the arrow keys.

Colors by a second value

To color the tiles by a second measure, set ColorValue: here each product's size is its revenue and its color the change from last year. A ChartPalette.Diverging palette turns at Midpoint (0 by default), here with growth in blue and decline in red.

Static

Preview

Sales by product, change from last year
  • −30% to −20%
  • −20% to −10%
  • −10% to 0%
  • 0% to +10%
  • +10% to +20%
  • +20% to +30%
Arrow keys move between tiles; Escape hides the tooltip.16 tiles in 5 groups, the largest Tents, $412,000

Code

Change.razor
@* An outdoor store's sales this year by product, sized by revenue and colored by the change from last year. *@
<TreemapChart Items="_sales"
              Name="s => s.Product"
              Value="s => s.Revenue"
              Group="s => s.Department"
              ColorValue="s => s.Change"
              Palette="ChartPalette.Diverging(Color.Danger, Color.Info)"
              Steps="6"
              ValueFormat="C0"
              ColorFormat="+0%;−0%;0%"
              Title="Sales by product, change from last year" />

@code {
    private record Sale(string Department, string Product, decimal Revenue, double Change);

    private readonly Sale[] _sales =
    [
        new("Camping", "Tents", 412000, 0.08),
        new("Camping", "Sleeping bags", 236000, 0.03),
        new("Camping", "Stoves", 98000, -0.06),
        new("Camping", "Lanterns", 54000, -0.14),
        new("Footwear", "Hiking boots", 388000, 0.12),
        new("Footwear", "Trail runners", 301000, 0.27),
        new("Footwear", "Sandals", 87000, -0.09),
        new("Clothing", "Rain jackets", 274000, 0.05),
        new("Clothing", "Fleece", 166000, -0.11),
        new("Clothing", "Base layers", 121000, 0.18),
        new("Clothing", "Hats", 46000, 0.01),
        new("Climbing", "Ropes", 142000, -0.03),
        new("Climbing", "Harnesses", 88000, 0.06),
        new("Climbing", "Chalk", 21000, 0.22),
        new("Water", "Kayaks", 158000, -0.19),
        new("Water", "Paddles", 39000, -0.07),
    ];
}

The colors fall into steps, as a HeatmapChart's do, and the legend above the tiles is the scale. Steps, Min and Max set it, and ColorFormat writes its values.

One level of tiles

Without Group, the tiles are one level, each in its own color so neighbors stand apart. AspectRatio sets the chart's shape, here 2.5 times as wide as tall.

Static

Preview

General fund by program
Arrow keys move between tiles; Escape hides the tooltip.22 tiles, the largest Patrol, $92M

Code

Budget.razor
@* A city's general fund for the year, by program: one level of tiles. *@
<TreemapChart Items="_programs"
              Name="p => p.Name"
              Value="p => p.Budget"
              ValueFormat="$#,##0,,.#M"
              Values
              AspectRatio="2.5"
              Title="General fund by program" />

@code {
    private record BudgetLine(string Name, decimal Budget);

    private readonly BudgetLine[] _programs =
    [
        new("Patrol", 92_000_000),
        new("Fire suppression", 61_000_000),
        new("Street maintenance", 38_000_000),
        new("Investigations", 31_000_000),
        new("Emergency medical", 27_000_000),
        new("Parks maintenance", 24_000_000),
        new("Solid waste", 21_000_000),
        new("Libraries", 18_500_000),
        new("Recreation centers", 15_500_000),
        new("Affordable housing", 14_000_000),
        new("Information technology", 12_500_000),
        new("Building inspections", 9_800_000),
        new("Finance", 9_200_000),
        new("Traffic signals", 8_400_000),
        new("City attorney", 7_100_000),
        new("Human resources", 6_300_000),
        new("Planning", 5_900_000),
        new("Code enforcement", 4_700_000),
        new("Animal services", 4_200_000),
        new("Emergency management", 2_600_000),
        new("City clerk", 2_100_000),
        new("Arts and culture", 1_800_000),
    ];
}

The chart keeps its shape at every width, so the tiles stay as square as they were laid out. Under 30rem wide it's square.

A treemap suits many parts, as the 22 programs here; with a handful, bars compare them better.

Drilling into tiles

To open a tile into what it's made of, put a ChartDrillLevel in the chart for each level in place of Name and Group. Select a category to see its services, laid out again at full size, and a service to see its environments.

Static

Preview

Cloud costs, 2026
Arrow keys move between tiles; Escape hides the tooltip. Enter opens the level below.5 tiles, the largest Compute, $344,400

Code

Drill.razor
@* A software company's cloud bill for the year, by category, then service, then environment:
   each tile opens what it's made of, laid out again at full size. *@
<TreemapChart id="cloud-drill" Items="_costs" Value="c => c.Amount" ValueFormat="C0" Values Title="Cloud costs, 2026" Drill="cloud">
    <ChartDrillLevel Argument="c => c.Category" Name="Category" />
    <ChartDrillLevel Argument="c => c.Service" Name="Service" />
    <ChartDrillLevel Argument="c => c.Environment" Name="Environment" />
</TreemapChart>

@code {
    private record Cost(string Category, string Service, string Environment, decimal Amount);

    // Each service's bill for the year, split between production and the environments that test it.
    private static readonly (string Category, string Service, decimal Yearly, decimal Production)[] Services =
    [
        ("Compute", "App servers", 220800, 0.72m), ("Compute", "Background jobs", 86400, 0.81m), ("Compute", "Build runners", 37200, 0.2m),
        ("Database", "Primary database", 151200, 0.78m), ("Database", "Read replicas", 75600, 1m), ("Database", "Cache", 28800, 0.66m),
        ("Storage", "Object storage", 62400, 0.85m), ("Storage", "Backups", 34800, 1m), ("Storage", "Block volumes", 21600, 0.6m),
        ("Network", "Data transfer", 73200, 0.93m), ("Network", "Load balancers", 18000, 0.5m), ("Network", "CDN", 14400, 1m),
        ("Monitoring", "Logs", 45600, 0.64m), ("Monitoring", "Metrics", 16800, 0.7m), ("Monitoring", "Tracing", 8400, 0.75m),
    ];

    // The rest of each bill, two parts staging to one part development; services only in production have no others.
    private static readonly Cost[] _costs = Services.SelectMany(s => new[]
    {
        new Cost(s.Category, s.Service, "Production", Math.Round(s.Yearly * s.Production)),
        new Cost(s.Category, s.Service, "Staging", Math.Round(s.Yearly * (1 - s.Production) * 2 / 3)),
        new Cost(s.Category, s.Service, "Development", Math.Round(s.Yearly * (1 - s.Production) / 3)),
    }.Where(c => c.Amount > 0)).ToArray();
}

Each tile adds up its items' values (Aggregate, Sum by default). The breadcrumb above the chart goes back up, and so does the browser's Back: the level is in the page's address, under the Drill key.

From the keyboard, move to a tile and press Enter. The data table's rows link to each tile's level, with no script too.

Details

Groups take the rectangle largest first, then each group's tiles take its space, the largest at the top left; tiles stay as near square as they can. The chart keeps its shape at every width (AspectRatio, 2:1 by default; square on a phone), so the tiles do too. Zero, negative and missing values are left out. Tiles take a color per group, or per tile without groups (Colors); ColorValue colors them by a second measure instead, such as the day's change on a market map, with a scale as HeatmapChart's. Each tile's name sits at its top left where it fits; Values adds its value. A treemap suits many parts of a whole; with a few, or when exact comparison matters, bars read better.

Mode support

What works in each mode, Treemap
FeatureStaticInteractive
Tiles as near square as they can be, the largest at the top leftYesYes
Groups of tiles, each under a strip with its nameYesYes
A color per group, or per tileYesYes
Tiles colored by a second value on a scale, such as the change from last year, with a legendYesYes
The same shape at every width, square on a phone, so the tiles stay squareYesYes
Each tile's name at its top left where it fits, and its value with ValuesYesYes
A table of every tile and its shares, in a "Show data" disclosureYesYes
Tooltips on tiles and group names, on hover and from the keyboardYesYes

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 tiles and group names, on hover and from the keyboard: waits for the script

Accessibility

  • The chart is a figure captioned by Title, or named by a heading on the page with TitledBy.
  • The tiles are one image named by the caption, described by their count and the largest.
  • "Show data" under the chart opens a table of every tile: its group, name, value and shares, and its ColorValue (DataTable).
  • Tiles are told apart by their names and places, not only by color.
  • With IzzyBlazor's script, the tiles are one Tab stop: the arrow keys move from tile to tile and say each one's value and shares.

Keyboard navigation

On the tiles

TreemapChart keys, On the tiles
Press this keyTo do this
Right or Left or Down or UpMove to the nearest tile that way
Home or EndGo to the first or last tile
EnterOpen the tile's level below (with ChartDrillLevels)
EscapeHide the tooltip

Parameters

TreemapChart 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?
DrillWith ChartDrillLevel<T>s (in place of Name and Group): the page address's query value that holds the level ("drill" by default; give each chart that drills on a page its own).string?
HideBreadcrumbWith drill-down levels: leaves out the breadcrumb above the chart.boolfalse
AggregateWith drill-down levels, how each tile adds up its items' values: Sum by default, or Avg, Min, Max or Count.DataAggregateDataAggregate.Sum
ItemsThe tiles, one item each: its name, its value and, with Group, its group.IEnumerable<TItem>?Required
NameEach tile's name, such as c => c.Service, written at its top left where it fits.Expression<Func<TItem, object?>>?
ValueEach tile's size, such as c => c.Amount: any positive number.Expression<Func<TItem, object?>>Required
GroupEach tile's group, such as c => c.Category.Expression<Func<TItem, object?>>?
ColorValueA second measure that colors the tiles, such as s => s.Change on a market map whose tiles are sized by market value: a scale of Palette's shades, as a HeatmapChart<T>'s, with a legend.Expression<Func<TItem, object?>>?
TitleThe chart's title, such as "Cloud costs by service", 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 C0 or N0: on the tiles, in the tooltips and the table.string?
ColorFormatA .NET format string for ColorValue, such as +0.0%;−0.0%;0.0%: in the legend, the tooltips and the table.string?
ColorsWhat colors the tiles: TreemapColors.Auto (the default) colors them by group with Group set, or each tile its own color without; TreemapColors.Group or TreemapColors.Item chooses (Group needs Group).TreemapColorsTreemapColors.Auto
PaletteThe colors: the theme's eight by default, repeating past eight, or your own with Of; Shades and Diverging throw.ChartPalette?
StepsWith ColorValue, about how many classes its values fall into, each a shade: 5 by default, 2 to 9 (the scale rounds its bounds, so one more or fewer), or 0 for a continuous blend.int5
MidpointWith ColorValue and a Diverging palette, the value the scale turns at: 0 by default.double?
MinWith ColorValue, the scale's low end.double?
MaxWith ColorValue, the scale's high end.double?
AspectRatioThe chart's width over its height: 2 by default (twice as wide as tall); from 0.5 to 4.double2
LabelsWrites each tile's name at its top left, where it fits.booltrue
ValuesWrites each tile's value under its name (with Labels), and each group's total beside its name.boolfalse
LegendWith ColorValue, where its scale goes: above the tiles by default (ChartLegend.Auto or ChartLegend.Top), ChartLegend.Bottom, or ChartLegend.None.ChartLegendChartLegend.Auto
LegendAlignWith ColorValue, the legend's place along its edge: the start by default, the center or the end.ChartAlign?
TooltipA tooltip for the tile or group name under the pointer, and the arrow keys from tile to tile, each saying its value and shares (with IzzyBlazor's script; with JavaScript off, a hover title).booltrue
DataTableThe tiles as a table: 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
ChildContentA ChartTooltip<T> for your own tile tooltips.RenderFragment?
OnRefreshOn an interactive page with Refresh: raised at each interval, to load new data.EventCallback

See also

  • PieChart: shows how one total splits into a few shares, such as customers by plan, each labeled with its share.
  • 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.

Connection lost

Rejoining the server…