Skip to content
misoto22 design

Charts

TreemapChart

Part of a whole, when the whole has too many parts for a pie — and the parts nest.

When to reach for it

Fifty items where a pie fails at six. Under a dozen items with a ranking to read, a BarChart’s length is the more precise encoding.

Examples

default

Bundle size by package
Bundle size by package
pathValue
recharts480
react-dom310
motion140
lucide-react96
cmdk62
tailwind-merge41
clsx12
sonner28

nested

Bundle size by group — nested
Bundle size by group — nested
pathValue
runtime › react-dom310
runtime › react92
charts › recharts480
charts › motion140
ui › lucide-react96
ui › cmdk62
ui › sonner28
ui › clsx12

Notes

Part of a whole, when the whole has too many parts for a pie — and the parts nest.

A treemap encodes value as AREA, which the eye reads worse than length but far better than angle, and it is the only form here that stays readable at fifty items. Two rules make it honest: no negative values (an area cannot be negative), and the tiles have to sum to something a reader recognises as the whole.

Reach for <BarChart> when there are under a dozen items and the ranking matters — a bar's length is the more precise encoding, and a treemap's layout deliberately does not order its tiles by value alone.

Props

TreemapChart props
PropTypeDefaultDescription
datarequiredTreemapNode[]The tree. One level is a flat set of tiles; two is a nested treemap.
titlerequiredstringWhat the chart shows, in a sentence a reader could act on. Required, and announced to a screen reader even when it is not printed.
aspectRationumber4 / 3How square the tiles are pushed to be. Recharts' own squarify parameter.
chartPropsTreemapExtras
childrenReactNodeThe hover panel.
classNamestringMerged onto the figure, last, so a call site can size or space it.
configChartConfig{}Tile names → their label and paint. Optional: the ramp covers unnamed tiles.
dataKeystring'size'The leaf field holding each tile's number.
descriptionReactNodeA line under the title — the unit, the window, the caveat.
hideDataTablebooleanfalseDrops the hidden table view. Only correct when the page prints the data itself.
showLabelsbooleantruePrints each tile's name on it, where the tile is big enough to hold it.
showTitlebooleanPrints the title above the plot instead of hiding it from sight.
variantTreemapVariant'ramp'

Types

TSX
export type TreemapVariant = 'ramp' | 'nested'
export type TreemapExtras = Omit<ComponentProps<typeof RechartsTreemap>, 'data' | 'dataKey'>

Accessibility

  • title is required. The table view lists the LEAVES with the path that names them: a nested tree read row by row is not something anyone can follow.
  • Area is the encoding, so the data must be non-negative and must sum to something the reader recognises as the whole.
  • The gap between tiles is a surface-coloured stroke rather than a smaller rect — a treemap whose parts do not touch stops reading as a partition.