Treemap

A treemap shows how a total splits into parts by area, when there are too many parts for a pie. Each item is a rectangle sized by its value, nested inside its group.

From paths

Give TreemapSeries each item's path from the outermost group as XValue, here "Asia/India". A group's value is the sum of its items, and its name sits in a header when there is room. Colors and legend items follow the top-level groups; click one in the legend to leave it out. GroupSmallItems gathers the smallest countries of each continent into "Other". Hover a rectangle for its share of the continent and of the world.

Click anywhere in a continent, even tiny Oceania, to drill into it: it fills the chart, its countries get their own colors, and the path bar above (All › Asia) leads back up. (When items take clicks themselves, with OnPointClick or Selection="ChartSelectionMode.Points", a group's header or frame drills instead.)

Treemap with 5 items: Asia 64%, Americas 14%, Africa 13%, Europe 9%, Oceania 1%. AsiaAfricaEuropeAmericasOceaniaAsia3982 MIndia1430 MChina1410 MOther327 MIndonesia278 MPakistan240 MBanglad…173 MJapanAmericas852 MUSA335 MBrazil216 MMexico129 MColom…Argent…Can…40 MPeruAfrica782 MNigeria224 MEthiopia127 MEgypt113 MDR Congo102 MTan…67 MKenya55 MEurope536 MRussia144 MGer…84 MUnite…68 MFrance68 MItaly59 MUse Left and Right to move between points. Press Escape to leave.
Code
Razor
<RioChart TItem="Country" Items="countries">
    <TreemapSeries Name="Population" XValue="@(c => $"{c.Continent}/{c.Name}")" YValue="c => c.Millions"
                   Format="0 M" GroupSmallItems="0.03" />
</RioChart>

@code {
    record Country(string Continent, string Name, double Millions);
}

From a parent-child list

With ParentValue, XValue is the item's name and the parent's name builds the path: folders on a disk, an organisation, a bill of materials. Names must then be unique. Only items with a value get a rectangle; a folder's own size is the sum of what is in it.

Deep trees get cramped, so VisibleLevels="2" draws two levels at a time: the top folders and what is in them. Photos shows as one cell with its total; open Home and its years appear. The data keeps every level.

Treemap with 3 items: Home 58%, Work 29%, System 13%. HomeWorkSystemHome498 GBPhotos ›228 GBVideos210 GBMusic48 GBDocu…12 GBWork252 GBArchive160 GBProjects74 GBMail18 GBSystem116 GBApps85 GBCache22 GBUse Left and Right to move between points. Press Escape to leave.
Code
Razor
<RioChart TItem="Folder" Items="folders">
    <TreemapSeries Name="Disk usage" XValue="f => f.Name" ParentValue="f => f.Parent" YValue="f => f.Gigabytes" Format="0 GB"
                   VisibleLevels="2" />
</RioChart>

@code {
    record Folder(string Name, string? Parent, double? Gigabytes); // Parent null: a top-level folder
}

Good to know

  • Zero and negative values are left out (the chart's screen reader text says how many); a treemap cannot show them as areas.
  • A flat list (no separator in the paths) is a one-level treemap; each item gets its own color and the legend stays hidden.
  • Names and values are shortened with "…" or hidden when a rectangle is too small; the tooltip always has them in full.
  • Use PathSeparator when names contain "/", e.g. PathSeparator=" > ".
  • Drill down from code with DrillDownAsync("Asia") (null for the whole tree), bind the group shown with @bind-TreemapPath (e.g. to keep it in the URL), and handle OnDrillDown to follow clicks, e.g. to load more detail.
  • Treemaps cannot be mixed with other series types, and only one treemap series is drawn.

In JSON definitions

"type": "treemap" with "path": ["continent", "country"] (the groups' fields, outermost first) and the value as y; or a single x field that holds the path. Rows with the same path are added up.

An unhandled error has occurred. Reload 🗙