Treemap
Since 0.1.0-alpha.22Use 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
| Category | Service | Amount | Share of group | Share of all |
|---|---|---|---|---|
| Compute | App servers | $18,400 | 64% | 25% |
| Compute | Background jobs | $7,200 | 25% | 10% |
| Compute | Build runners | $3,100 | 11% | 4.2% |
| Database | Primary database | $12,600 | 59% | 17% |
| Database | Read replicas | $6,300 | 30% | 8.4% |
| Database | Cache | $2,400 | 11% | 3.2% |
| Storage | Object storage | $5,200 | 53% | 7.0% |
| Storage | Backups | $2,900 | 29% | 3.9% |
| Storage | Block volumes | $1,800 | 18% | 2.4% |
| Network | Data transfer | $6,100 | 69% | 8.2% |
| Network | Load balancers | $1,500 | 17% | 2.0% |
| Network | CDN | $1,200 | 14% | 1.6% |
| Monitoring | Logs | $3,800 | 64% | 5.1% |
| Monitoring | Metrics | $1,400 | 24% | 1.9% |
| Monitoring | Tracing | $700 | 12% | 0.9% |
Code
@* 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" />
{
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:
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
- −30% to −20%
- −20% to −10%
- −10% to 0%
- 0% to +10%
- +10% to +20%
- +20% to +30%
| Department | Product | Revenue | Share of group | Share of all | Change |
|---|---|---|---|---|---|
| Camping | Tents | $412,000 | 52% | 16% | +8% |
| Camping | Sleeping bags | $236,000 | 29% | 9.0% | +3% |
| Camping | Stoves | $98,000 | 12% | 3.7% | −6% |
| Camping | Lanterns | $54,000 | 6.8% | 2.1% | −14% |
| Footwear | Hiking boots | $388,000 | 50% | 15% | +12% |
| Footwear | Trail runners | $301,000 | 39% | 11% | +27% |
| Footwear | Sandals | $87,000 | 11% | 3.3% | −9% |
| Clothing | Rain jackets | $274,000 | 45% | 10% | +5% |
| Clothing | Fleece | $166,000 | 27% | 6.3% | −11% |
| Clothing | Base layers | $121,000 | 20% | 4.6% | +18% |
| Clothing | Hats | $46,000 | 7.6% | 1.7% | +1% |
| Climbing | Ropes | $142,000 | 57% | 5.4% | −3% |
| Climbing | Harnesses | $88,000 | 35% | 3.3% | +6% |
| Climbing | Chalk | $21,000 | 8.4% | 0.8% | +22% |
| Water | Kayaks | $158,000 | 80% | 6.0% | −19% |
| Water | Paddles | $39,000 | 20% | 1.5% | −7% |
Code
@* 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" />
{
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
| Name | Budget | Share of all |
|---|---|---|
| Patrol | $92M | 22% |
| Fire suppression | $61M | 15% |
| Street maintenance | $38M | 9.1% |
| Investigations | $31M | 7.4% |
| Emergency medical | $27M | 6.5% |
| Parks maintenance | $24M | 5.8% |
| Solid waste | $21M | 5.0% |
| Libraries | $18.5M | 4.4% |
| Recreation centers | $15.5M | 3.7% |
| Affordable housing | $14M | 3.4% |
| Information technology | $12.5M | 3.0% |
| Building inspections | $9.8M | 2.4% |
| Finance | $9.2M | 2.2% |
| Traffic signals | $8.4M | 2.0% |
| City attorney | $7.1M | 1.7% |
| Human resources | $6.3M | 1.5% |
| Planning | $5.9M | 1.4% |
| Code enforcement | $4.7M | 1.1% |
| Animal services | $4.2M | 1.0% |
| Emergency management | $2.6M | 0.6% |
| City clerk | $2.1M | 0.5% |
| Arts and culture | $1.8M | 0.4% |
Code
@* 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" />
{
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
| Category | Amount | Share of all |
|---|---|---|
| Compute | $344,400 | 38% |
| Database | $255,600 | 29% |
| Storage | $118,800 | 13% |
| Network | $105,600 | 12% |
| Monitoring | $70,800 | 7.9% |
Code
@* 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>
{
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
| Feature | Static | Interactive |
|---|---|---|
| Tiles as near square as they can be, the largest at the top left | Yes | Yes |
| Groups of tiles, each under a strip with its name | Yes | Yes |
| A color per group, or per tile | Yes | Yes |
| Tiles colored by a second value on a scale, such as the change from last year, with a legend | Yes | Yes |
| The same shape at every width, square on a phone, so the tiles stay square | Yes | Yes |
| Each tile's name at its top left where it fits, and its value with Values | Yes | Yes |
| A table of every tile and its shares, in a "Show data" disclosure | Yes | Yes |
| Tooltips on tiles and group names, on hover and from the keyboard | 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 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 withTitledBy. - 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
| Press this key | To do this |
|---|---|
| Right or Left or Down or Up | Move to the nearest tile that way |
| Home or End | Go to the first or last tile |
| Enter | Open the tile's level below (with ChartDrillLevels) |
| Escape | Hide the tooltip |
Parameters
| Prop | Type | Default |
|---|---|---|
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. | bool | false |
AggregateWith drill-down levels, how each tile adds up its items' values: Sum by default, or Avg, Min, Max or Count. | DataAggregate | DataAggregate.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. | bool | false |
DownloadShows a button across from the title that saves the chart as a PNG, named after its title, in the color scheme on screen. | bool | false |
TitleAlignWhere the title sits: at the start by default (the left, in a left-to-right page); ChartAlign.Center or ChartAlign.End. | ChartAlign | ChartAlign.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). | TreemapColors | TreemapColors.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. | int | 5 |
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. | double | 2 |
LabelsWrites each tile's name at its top left, where it fits. | bool | true |
ValuesWrites each tile's value under its name (with Labels), and each group's total beside its name. | bool | false |
LegendWith ColorValue, where its scale goes: above the tiles by default (ChartLegend.Auto or ChartLegend.Top), ChartLegend.Bottom, or ChartLegend.None. | ChartLegend | ChartLegend.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). | bool | true |
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. | ChartDataTable | ChartDataTable.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 |
Plus 17 item props and 4 common props.
Full APISee 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.