Skip to content

Treemap Chart

React squarified SVG treemap with grouped cells under header strips, labels that hide in small cells, a value tooltip on hover or focus and a data table.

src/registry/ui/treemap-chart.tsx/r/treemap-chart.json

Installation

bash
npx shadcn@latest add @minidev/treemap-chart

MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/treemap-chart.json

Usage

tsx
import { TreemapChart } from "@/components/ui/treemap-chart"

export function Example() {
  return (
    <TreemapChart />
  )
}

API reference

TreemapChart props
PropTypeDefault
dataTop level items. A node with `children` renders as a group with a header strip.TreemapNode[]SAMPLE
titleHeading above the chart and the accessible name.string"Revenue by product line"
captionShown next to the total.string"October, by plan"
heightChart height in px. The width follows the container.number320
formatFormats values in the tooltip, labels and table. Defaults to compact USD ("$48.2K").(value: number) => stringdefaultFormat
valueLabelName of the measure in the tooltip, e.g. "Revenue", "Storage", "Users".string"Revenue"
minLabelSizeHide labels in cells narrower or shorter than this, in px.number44
classNamestring-

Keyboard interactions

Keyboard interactions
KeyAction
TabMoves focus into the treemap. All cells share one Tab stop.
ArrowRightorArrowDownMoves focus to the next cell and shows its tooltip.
ArrowLeftorArrowUpMoves focus to the previous cell.
HomeorEndMoves focus to the first or last cell.

Accessibility

  • The chart is a <figure> labelled by its title; the SVG is role="group" named with the cell count.
  • Each cell is a focusable role="img" named with its group, item, formatted value and share of the total, in that order.
  • The tooltip and in-cell text are aria-hidden because the cell's name carries the same numbers.
  • A visually hidden <table> lists group, item, value and share for every cell, with a total row.

Frequently asked questions

Can TreemapChart nest more than one level deep?

No. A top-level item is either a leaf ({ label, value }) or a group with children leaves, and groups get a header strip when there is room. For deeper data, flatten it to two levels or let people pick a group and pass only its children.

How are cell colours chosen?

Each top-level item takes the next chart token, --chart-1 to --chart-5, unless you set color. Leaves inherit their group's colour at a strength set by their rank in the group, so the largest child is the strongest. A leaf's own color overrides that.

Does clicking a cell drill down?

No. Cells respond to hover and focus with a tooltip; there is no click handler. Treat it as a read-only chart and put drill-down links in a table next to it.

Why are some cells unlabelled?

Labels hide in cells narrower than minLabelSize (default 44px) or shorter than 26px, and the value line needs 44px of height, so text never overflows. Hover or focus the cell to see its tooltip; screen readers always get the full label.

Examples

Flat data

Leaves without children render as one level; format rewrites every value so the chart can show gigabytes instead of money.

Group colours and counts

A color on a group tints all of its cells; here the values are customer counts, so format drops the currency.

All chart components