Skip to content
EspañolEnglish
All components (283)

Treemap

Data · TreemapChart · .amset-treemap

What it is and when to use it

The parts of a total as rectangles: sales by category, space by folder. It holds many more parts than a DonutChart, and the area of each rectangle is proportional to its value.

When to use it

  • Many parts of a total, to see which weigh most.
  • items are the parts: { key, label, value, tone? }.

When not to

  • Few parts: DonutChart, which reads faster.
  • Comparing values precisely: BarChart. The eye compares areas badly.

Keyboard: Tab takes you to the drawing and the arrows move from part to part, from largest to smallest, with a spoken notice.

Accessibility: it is an image (role="img") with a written summary, and underneath goes a real table. A part that is too small has no name: it stays in the tooltip and the table.

Fine-tuning: --amset-treemap-height is the height.

What it looks like

Use the arrow keys to move through the values, Home and End to jump to the first and last, and Escape to leave.
Sales by category
PartValueShare of total
Rings48.200 €34.1%
Necklaces31.500 €22.3%
Earrings22.400 €15.8%
Bracelets15.800 €11.2%
Watches12.100 €8.6%
Brooches6200 €4.4%
Cases3900 €2.8%
Engravings1400 €1%

<TreemapChart
  label="Sales by category"
  items={[
    { key: "anillos", label: "Rings", value: 48200 },
    { key: "necklaces", label: "Necklaces", value: 31500 },
    { key: "earrings", label: "Earrings", value: 22400 },
  ]}
  format={enEuros}
/>

Props

Import it with import { TreemapChart } from '@amset/ui'. Required props are marked.

PropTypeWhat it does
itemsrequiredreadonly TreemapItem[]The parts: `{ key, label, value, tone? }`. What is not positive is not drawn.
labelrequiredstringWhat is being measured. Required: a chart without a title does not inform.
classNamestringMerged with the library classes; it does not replace them.
errorReactNodeThe data has not arrived: it says so in the place of the drawing, with what is passed here.
format(value: number) => string—
loadingbooleanThe data is on its way.
tableVisiblebooleanAlso shows the table. For the screen reader it is always there.

It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.

CSS variables

These CSS variables are how you adapt it. Declare them on the component's selector, not on :root: the stylesheet redeclares them in the rule itself, and a declaration on the same element always wins.

VariableDefault
--amset-treemap-height18rem

How to change it

.amset-treemap {
  --amset-treemap-height: ...;
}

In the test bench

Every state and variant, to try one at a time, on its page at storybook.amsetui.com: