Skip to content
WunderUI

Treemap

Pro

Treemap for the parts of a hierarchy: squarified, nested with group headers, or as an icicle.

Playground

Revenue by line

Revenue by product line: 12 parts, total $1.8M. Largest: Enterprise $410k, Core $340k, Pro $260k.
Revenue by product line, data table
labelPathValueShare
CoreSoftware › Core$340k18.4%
ProSoftware › Pro$260k14.1%
EnterpriseSoftware › Enterprise$410k22.2%
Add-onsSoftware › Add-ons$90k4.9%
OnboardingServices › Onboarding$120k6.5%
TrainingServices › Training$80k4.3%
SupportServices › Support$150k8.1%
DevicesHardware › Devices$180k9.8%
AccessoriesHardware › Accessories$60k3.3%
TemplatesMarketplace › Templates$70k3.8%
PluginsMarketplace › Plugins$55k3%
ThemesMarketplace › Themes$30k1.6%

Installation

Treemap comes with WunderUI Core and Pro, in the package from your plan. See the plans.

The charts live in their own entry point: import the chart, its card and its hooks from @wunderui/react/charts, not from @wunderui/react.

Then import what you need:

tsx
import {
  TreemapChart,
  TreemapChartProps,
  TreemapChartVariant,
} from "@wunderui/react/charts"

Then use it:

tsx
import { TreemapChart } from "@wunderui/react/charts"

const data = {
  name: "Revenue",
  children: [
    { name: "Software", children: [{ name: "Core", value: 340 }, { name: "Pro", value: 260 }] },
    { name: "Services", children: [{ name: "Onboarding", value: 120 }, { name: "Support", value: 150 }] },
  ],
}

export function RevenueByLine() {
  return <TreemapChart data={data} label="Revenue by product line" />
}

Expected result: Four rectangles in two colours, with the Software ones the largest.

When to use

Use Treemap for

  • The parts of a hierarchy by size: revenue by line and product, disk usage
  • Many leaves that would be too small for a pie
  • A nested view with group headers, or an icicle by level

Use something else for

  • Sunburst for a hierarchy as rings, with a centre value
  • Pie Chart for five parts or fewer of one whole
  • Stacked Chart for parts of a total per period
  • Heatmap for a value for every pair of two categories

States

Loading, empty and error keep the chart's size, so the card never jumps. Add a retry handler and the error state offers a Try again button.

Revenue by line

Revenue by product line: 12 parts, total $1.8M. Largest: Enterprise $410k, Core $340k, Pro $260k.
Revenue by product line, data table
labelPathValueShare
CoreSoftware › Core$340k18.4%
ProSoftware › Pro$260k14.1%
EnterpriseSoftware › Enterprise$410k22.2%
Add-onsSoftware › Add-ons$90k4.9%
OnboardingServices › Onboarding$120k6.5%
TrainingServices › Training$80k4.3%
SupportServices › Support$150k8.1%
DevicesHardware › Devices$180k9.8%
AccessoriesHardware › Accessories$60k3.3%
TemplatesMarketplace › Templates$70k3.8%
PluginsMarketplace › Plugins$55k3%
ThemesMarketplace › Themes$30k1.6%

Keyboard interactions

The plot is focusable. Arrow keys step through the leaves and the live region reads the part with its path and share of the total, such as Software › Core: 340, 23.3%.

TaborShiftTab
Moves focus to the plot and away from it. The plot is one tab stop; so is every legend badge.
ArrowRightorArrowLeft
Moves to the next or previous leaf. The tooltip follows, and a live region announces the one you are on. The first press starts at the first one (Left: the last one).
HomeorEnd
Jumps to the first or last leaf.
Escape
Clears the active point.
EnterorSpace
On a legend badge of a ChartCard: switches its series off or on. The last visible series stays on.

Behavior and motion

What the chart does on its own and what the page decides.

Data
Data is a tree: a name, a value on the leaves, children and an optional colour. The top-level children are the coloured groups, and a tree with no positive values counts as empty.
Labels
Cells are rounded with a small gap. Labels appear only in cells with room for them, and the others rely on the tooltip.
Variants
The basic treemap shows the leaves, the nested treemap adds a header strip per group, and the icicle runs the levels as rows from the root.
Legend
Hidden series fade whole groups by name. Helpers for the hierarchy rows and group colours are exported for building a matching legend.
Loading, empty and error
The chart keeps its size while it loads, is empty or fails, so the card never jumps. Loading shows a muted shimmer, and an error shows a Try again button when you add a retry handler.
Legend
A ChartCard shows the series as badges. With two or more series each badge switches its series off and the last visible one stays on, and a legend of roles instead of series can be made static.
Size
The chart fills the width of its container, and you set the plot height. Text never scales, so labels keep their size at every width.

Motion

The enter sequence and the hover follow the library's motion tokens.

Fade in
Cells fade in the first time the chart is in view, and again after loading, on a key change or when new data arrives. You can turn it off.
Reduced motion
With reduced motion the enter sequence is off and the chart appears at once. The tooltip, crosshair and every state still work.

Anatomy

TreemapChart shows a hierarchy as nested rectangles whose area is the value: a treemap of the leaves, a nested treemap with group headers, or an icicle. The top-level children are the coloured groups.

Revenue by line

Revenue by product line: 8 parts, total $1600k. Largest: Enterprise $410k, Core $340k, Pro $260k.
Revenue by product line, data table
labelPathValueShare
CoreSoftware › Core$340k21.3%
ProSoftware › Pro$260k16.3%
EnterpriseSoftware › Enterprise$410k25.6%
OnboardingServices › Onboarding$120k7.5%
TrainingServices › Training$80k5%
SupportServices › Support$150k9.4%
DevicesHardware › Devices$180k11.3%
AccessoriesHardware › Accessories$60k3.8%
  • Takes a tree of data (name, a value on the leaves, children and an optional colour). Hidden series fade whole groups, and helpers are exported for building a matching legend.

  • data-slot="chart-plot"

    The focusable region. Arrow keys walk its marks and the live region reads each one the way the tooltip shows it.

  • data-slot="chart-marks"

    Rounded cells with a small gap, fading in. Labels appear only in cells with room for them, and the others rely on the tooltip.

  • Optional

    In the nested treemap, a header strip per group with its name. In the icicle, the levels run as rows from the root.

  • data-slot="chart-tooltip"Optional

    The cell's group with its value and its share of the total.

  • data-slot="chart-message"Optional

    Muted bars under the shimmer. A tree with no positive values counts as empty.

  • A table of the leaves with their groups and values.

Best practices

  • Do

    Keep to two levels. Deeper trees make cells too small to label, so collapse the long tail into one Other leaf.

  • Do

    Colour by top-level group only and keep the groups to five or six. Colour per cell carries no information.

  • Do

    Pass positive values and a clear root name. Zero and negative leaves aren't drawn.

  • Don’t

    Don't use a treemap to compare close values. Area is read less accurately than length, and cells of similar size can't be ranked by eye.

  • Don’t

    Don't rely on labels inside small cells. Put the important numbers in the card or the table.

API reference

One table for TreemapChart. It is a plain component, so the table lists every prop, and the ChartCard around it takes its own props and works without one.

Takes a tree of data (name, a value on the leaves, children and an optional colour). Hidden series fade whole groups, and helpers are exported for building a matching legend.

PropTypeDefaultDescription
data requiredHierarchyDatum—Root of the hierarchy; its children are the coloured groups.
variant"basic-treemap" | "nested-treemap" | "icicle""basic-treemap"Figma variant. Default .
valueFormatterChartValueFormatter—
labelstring—
heightnumber—
state"ready" | "loading" | "empty" | "error"—
hiddenSeriesreadonly string[]—Group names switched off in the legend: their cells fade.
activeIndexnumber | null—The active point (hovered or focused) as an index into , to control it yourself. shows none.
animateboolean—
animationKeystring | number—
defaultActiveIndexnumber | null—The point that is active at first, for an uncontrolled chart. It shows the tooltip without a pointer.
descriptionstring—
onActiveIndexChange(index) => void—Called with the index when the pointer or the arrow keys move to another point, and with when they leave. Use it to show the hovered value in a headline.
onRetry() => void—Shows a Try again button in the error state and calls this when it is pressed.
widthnumber—

Notes for AI

Give your coding assistant the Markdown reference instead of screenshots.

MCPget_component("treemap")
InstallIncluded in Core and Pro

The full library index for assistants is at /llms.txt.