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.
itemsare 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
| Part | Value | Share of total |
|---|---|---|
| Rings | 48.200 € | 34.1% |
| Necklaces | 31.500 € | 22.3% |
| Earrings | 22.400 € | 15.8% |
| Bracelets | 15.800 € | 11.2% |
| Watches | 12.100 € | 8.6% |
| Brooches | 6200 € | 4.4% |
| Cases | 3900 € | 2.8% |
| Engravings | 1400 € | 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.
| Prop | Type | What it does |
|---|---|---|
itemsrequired | readonly TreemapItem[] | The parts: `{ key, label, value, tone? }`. What is not positive is not drawn. |
labelrequired | string | What is being measured. Required: a chart without a title does not inform. |
className | string | Merged with the library classes; it does not replace them. |
error | ReactNode | The data has not arrived: it says so in the place of the drawing, with what is passed here. |
format | (value: number) => string | — |
loading | boolean | The data is on its way. |
tableVisible | boolean | Also 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.
| Variable | Default |
|---|---|
--amset-treemap-height | 18rem |
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:
