Treemap for React
A React treemap shows part-to-whole as nested rectangles, laid out by the squarified algorithm so tiles stay easy to compare. Pass data as readonly TreemapNode[]: nodes: leaves carry a value; groups carry children (any depth).
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/treemap.jsonCloud spend
TreemapTreemapTablesquarifytreemapLegenddefaultTreemapLabels- +4 more
- +1 more
Cloud spend, zoomable
Each team keeps one palette slot and its services share the hue. Click a team (or focus the chart, move with the arrow keys and press Enter) to zoom in; the breadcrumb or Escape zooms back out. Switching the quarter re-flows the tiles.
Cloud spend
Q4 2026, by team and service
- Engineering
- Data
- Product
- Security
import { useState } from "react";
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
import { formatCompact } from "@/components/sheenui/charts/chart-utils";
import { treemapLegend, TreemapTable, Treemap, type TreemapNode } from "@/components/sheenui/charts/treemap";
// Package build (after the first npm release, or a packed tarball): import { ChartCard, formatCompact, treemapLegend, TreemapTable, Treemap, type TreemapNode } from "@sheenui/theme";
const usd = (n: number) => "$" + formatCompact(n);
const spend: TreemapNode[] = [
{
label: "Engineering",
color: 1,
children: [
{ label: "Compute", value: 158000 },
{ label: "Storage", value: 64000 },
{ label: "CDN", value: 21000 },
],
},
{
label: "Data",
color: 7,
children: [
{ label: "Warehouse", value: 92000 },
{ label: "Streaming", value: 37000 },
],
},
{
label: "Support",
color: 3,
children: [
{ label: "Tooling", value: 18000 },
{ label: "Telephony", value: 12000 },
],
},
];
export function Example() {
const [path, setPath] = useState<string[]>([]);
return (
<ChartCard
title="Cloud spend"
legend={treemapLegend(spend)}
table={<TreemapTable data={spend} format={usd} />}
>
<Treemap
data={spend}
format={usd}
path={path} // optional: control the zoom level
onPathChange={setPath}
aria-label="Cloud spend by team and service"
/>
</ChartCard>
);
}Files to copy
12 folders · 27 files · 4 packages
- From
theme/src/ components/charts/{treemap.tsx, chart-export-menu.tsx, chart-export.ts, chart-figure.tsx, chart-fit.tsx, chart-icons.tsx, chart-parts.tsx, chart-patterns.tsx, chart-tip.tsx, chart-utils.ts, heatmap.tsx}components/charts/chart-parts/components/charts/heatmap/components/drawer/parts/sheet.tsxcomponents/kbd/components/menu/components/skeleton/components/status-icons/hooks/{use-controllable.ts, use-intersection.ts, use-latest.ts, use-media-query.ts, use-preferences.ts}motion/tokens.tslib/{cn.ts, csv.ts, form.ts, glide-highlight.tsx, heading.ts, math.ts, popup-a11y.ts, popup-motion.ts, warn-once.ts}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/treemap.jsonRegistry item: treemap. The styles need the Tailwind v4 glass UI setup.- The examples also use
components/spinner/components/toast/hooks/use-direction.tslib/state-light.tsx
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/toast.json- Packages
pnpm add @base-ui/react clsx motion tailwind-merge
Next.js: samples here pass functions (formatters, seriesLegend, a dashboard's load), so put them in a file that starts with "use client".
Flat data, one hue
Without groups every tile is the same series, so it takes one hue and needs no legend; size alone carries the value. Tiny tiles stay unlabelled rather than overflow, and the tooltip and table still read them. Click a tile to handle it.
Bundle size
Gzipped kB by package
import { Treemap, type TreemapNode } from "@/components/sheenui/charts/treemap";
import { useToast } from "@/components/sheenui/toast/toast";
// Package build (after the first npm release, or a packed tarball): import { Treemap, useToast, type TreemapNode } from "@sheenui/theme";
// This example also uses toast: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/toast.json
const bundle: TreemapNode[] = [
{ label: "react-dom", value: 132 },
{ label: "motion", value: 58 },
{ label: "lucide-react", value: 34 },
{ label: "date-fns", value: 21 },
{ label: "zod", value: 14 },
];
export function Example() {
const toast = useToast();
return (
<Treemap
data={bundle}
color={7}
format={(n) => `${n} kB`}
onNodeClick={(node) => toast.info(node.label)}
aria-label="JavaScript bundle size by package"
/>
);
}Treemap
TreemapLabels keys and English defaults (10)
TreemapTable props, treemapLegend and squarify
TreemapTableLabels keys and English defaults (1)
Keyboard
Accessibility
- The chart is a focusable figure named by its aria-label and described by the reading hint (and the drill-down hint when it is on); zooming is announced, and the breadcrumb is real buttons.
- TreemapTable is the table view: pair it with ChartCard's table prop (Chart / Table tabs) so every value can be read without color or sight. It lists every node.
- Reduced motion: the tiles appear at their final sizes and data changes jump instead of morphing.
All exports on this page
Treemap— Part-to-whole as nested rectangles, laid out with the squarified algorithm so tiles stay close to square (and comparable).TreemapTable— Every node, depth first (groups in bold, children indented), with its value and shares.defaultTreemapLabels— The built-in English strings of Treemap; spread it into your own labels and change what you need.defaultTreemapTableLabels— English defaults of TreemapTableLabels.squarify— Lays values out inside rect as rectangles whose areas are proportional to the values.treemapLegend— Legend items for a hierarchical treemap's top-level groups (pass to ChartCard's legend).
When to use Treemap
- Use it as a treemap chart in React for cloud spend by team and service, where each team keeps one hue, services share it, and tile area shows where the money goes.
- It fits a portfolio or inventory with a natural hierarchy, such as product categories and SKUs, where clicking a group zooms in and the breadcrumb or Escape zooms back.
- Flat data also works: without groups every tile uses one hue and needs no legend, so size alone carries the value.
- Skip it when exact comparison or time trends matter, since area is hard to judge; use BarChart for comparisons, and SunburstChart when the path through the hierarchy matters more than area.
- Pair it with ChartCard for the title, treemapLegend for the top-level group legend, and TreemapTable for every node as text with percent of group and total.
Frequently asked questions
Related pages
48 charts pages in all: browse them on Charts.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .