Skip to content
InsightCharts

Search

Search guides and components

Treemap

Shows parts of a whole as nested rectangles sized by value, optionally grouped into categories.

Use when
Many parts (10 to 100) of very different sizes, or a two-level hierarchy, where the reader needs the largest parts rather than exact comparison: budgets, market capitalisation, export baskets.
Avoid when
Fewer than about 6 parts or values that need precise comparison (use bar chart); 2 to 5 parts (use donut chart or segmented bar); values that can be negative (use bar chart); change over time (use line chart).

Preview

Energy produced 75% of global greenhouse gas emissions in 2021

Global emissions by sector and source, billion tonnes of CO2 equivalent, 2021

Source: Climate Watch, World Resources Institute · Rounded, approximate figures for illustration

Composition

Used in

1 molecule and 3 infographics use treemap.

Molecules

1

The sheet an infographic is composed on. It paints a full-bleed ground from a poster theme, forces one theme and colour mode on everything inside, and lays out a masthead, a grid of panels and a footer. It can save the whole sheet as one PNG.

Infographics

3

A landscape spread of up to eleven small illustrations of one subject, each a different graphic form, in three bands of unequal panels: a statement in large type, spokes round an icon and a network of circles; a smooth trend with its peak labelled, nested squares and a slope chart; a pill ranking, a treemap, a tile map and sized circles; and a closing row of icon statements.

A portrait poster of where something comes from and where it goes, in three stacked bands painted in one colour: the producers as large labelled tiles, the leading producer's output fanning out as ribbons to an aligned column of destinations, and the destinations as bubbles on a scale of how much each depends on that producer.

A poster of one subject by the numbers, in four rows: two figures in large type or as filled silhouettes, two treemaps side by side, a full-width ranking of centred pills with one row highlighted, and packed circles with icons beside a column of sized circles and a closing figure.

Installation

$ pnpm dlx shadcn@latest add @insightcharts/treemap

The CLI copies the source into your project and needs the @insightcharts registry in components.json; see installation. With the package, import it by name:

import { Treemap } from "insightcharts";

Examples

Flat, with highlight

Apple, Nvidia and Microsoft were worth $9.8 trillion combined in late 2024

Market capitalisation of the 15 largest US-listed companies, late 2024, $ trillion

Source: Company filings, exchange data · Rounded, illustrative

Stress: many small tiles and long names

Social protection was £306bn of £910bn in UK public spending in 2023-24

Public spending by area and programme, £ billion, 2023-24

Source: HM Treasury Public Expenditure Statistical Analyses · Programme split is illustrative

Props

PropTypeDefaultDescription
namerequiredstringLeaf name field: one tile per row.
valuerequiredstringValue field: tile area. Non-positive values are dropped.
groupstringParent field. Rows sharing a group are drawn together and share a colour.
labelsbooleantruePrint the value under the name where the tile is big enough.
groupLabelsbooleanHeading strip above each group. Default: on when group is set and not compact.
namesRecord<string, string>Display names for group keys.
Common chart props 29

Every chart built with defineChart accepts these on top of its own props.

PropTypeDescription
dataDataInputRows, CSV text, a URL, { url, path }, an async function, or an Arrow-style table. Omit inside <InsightData>.
transformTransform | Transform[]A pipeline of transforms applied before drawing.
titlestringThe title. One plain statement of what the data shows, with the number and the period ("Monthly churn fell from 4.2% to 2.1% in 2024"), or a plain label ("Monthly churn, 2024"). One clause, no figures of speech.
subtitlestringMeasure, unit, population, period.
sourcestringData source, shown as "Source: ...".
notestringMethod notes or caveats.
heightnumber | stringCSS height of the plot. Default 360.
aspectnumberWidth / height. Overrides height.
highlightstring | string[]The entity (or entities) the title is about. Every other series is drawn in grey.
annotationsAnnotation[]Reference lines, shaded bands and callouts, in data coordinates.
formatFormatSpecHow to print values: "compact", "percent", "currency:USD", "{value} kg", Intl options, or a function.
legendbooleanShow the legend. Default: shown when there are two or more series.
selectboolean | stringMake marks clickable to filter. Inside <InsightData> the selection filters every other chart. Pass a field name, or true to use the chart's category field.
onSelect(values: string[], field: string) => voidCalled with the selected values whenever the selection changes.
optionEChartsOption | ((option: EChartsOption, ctx: BuildContext) => EChartsOption)Deep-merged over the generated ECharts option, or a function that receives and returns it. Use it for ECharts settings no prop covers.
themeThemeInputA theme, or a partial set of tokens merged over the surrounding theme, for this chart only.
modeModeInput"auto" (default) follows the page, "system" follows the OS, or force "light" / "dark".
rendererRendererInput"auto" (default) uses SVG for light charts and canvas for heavy ones.
animatebooleanSet false to disable animation. Reduced-motion preferences are always respected.
lazybooleanMount the chart only when it scrolls near the viewport. Default true.
groupstringLink tooltips with other charts sharing this group id.
exportableboolean | ExportFormat[]Show an export menu: true or a list of formats from png, jpeg, svg, pdf, csv, json.
tablebooleanShow a collapsible "View data" table under the chart.
altstringAccessible description: the chart type and measures, then the main pattern and the notable values.
idstringStable id for this chart's selection in the shared store.
onEventsRecord<string, ChartEventHandler>ECharts event handlers, e.g. { click: (params, chart) => {} }. Prefix a name with zr: to bind to the canvas itself.
onReady(chart: EChartsInstance) => voidCalled with the ECharts instance once it is created.
classNamestringClass name for the outer <figure>.
styleCSSPropertiesInline style for the outer <figure>.