Basic treemap example
treemap-beta
"Annual budget"
"Engineering"
"Salaries": 600
"Cloud": 150
"Tools": 50
"Marketing"
"Ads": 200
"Events": 80
"Operations"
"Office": 120
"Legal": 40Treemaps display hierarchical data as nested rectangles, where each rectangle's area is proportional to its value. They make it easy to see which parts of a whole are biggest at every level.
Typical uses include budgets by department, disk usage by folder, bundle sizes by package and portfolio allocations.
When to use a treemap
- Budget allocation by department
- JavaScript bundle size analysis
- Disk usage by folder
- Portfolio allocation
Treemap syntax reference
| Syntax | What it does |
|---|---|
treemap-beta | Start a treemap. |
"Section" | A parent node (indent children beneath it). |
"Leaf": 42 | A leaf node with a value. |
classDef / :::class | Style nodes with classes. |
Treemap examples
Area is the number. A mermaid treemap turns a tree of values into nested rectangles, so the big parts of a whole are big on the page. A mindmap can show the same nesting and can't show that engineering is twice operations. The indent is the tree. The number is the size.
Parents, leaves, and indent
treemap-beta opens the chart. A quoted line with no number is a parent, such as "Budget". A quoted line with a colon and a number is a leaf: "Eng": 40. Children are indented under their parent, two spaces per level, in the same spirit as a mindmap.
Parents don't need a value. The rectangle for a parent is the sum of its leaves. If you type a number on the parent and also give it children, you have two ideas of the size. Let the leaves be the only numbers. Then the parent area is earned by addition, and a reader can check it.
Two levels are the sweet spot: a whole, then a few parts. Three levels still work when a part has real sub-parts, such as engineering split into pay and cloud. Deeper than that, the small rectangles lose their labels. Roll the tiny leaves into a sibling called "Other" or move them to a table.
Values should share a unit. Dollars mixed with headcount will make the larger unit eat the chart. The diagram doesn't know the unit. The title or the root label has to say it.
Worked example
A budget splits into engineering and operations. Engineering itself splits into pay and cloud. Operations is a single leaf.
treemap-beta
"Budget"
"Eng"
"Pay": 40
"Cloud": 10
"Ops": 20Budget is the root and has no number. Eng is a parent, also without a number, and its area is 40 plus 10. Ops is 20, a leaf beside Eng, so it's a sibling of engineering rather than a child of it. That indent is the modeling choice. If Ops were indented under Eng, the chart would say operations is part of engineering, and the engineering rectangle would grow to 70.
Pay is the largest leaf, so it should dominate the engineering block. Cloud is a quarter of Pay, and Ops is a third of the whole 70. You can check those fractions from the source in a few seconds. If the picture disagrees, the indent is wrong before the renderer is wrong.
The root label "Budget" doesn't say dollars or percent. Add that in the title line of the doc, or rename the root to something that includes the unit if the labels stay short. A treemap without a unit invites a reader to treat area as importance rather than money.
When this is the wrong diagram
A pie chart is the better picture when the parts are one flat list and you don't need nesting. A sankey diagram is the better picture when the quantity flows from a source to a target instead of sitting inside a parent. Use a treemap when the hierarchy and the size both matter.
Common mistakes
- Indenting a sibling under the wrong parent.
"Ops": 20at Eng's indent is a child of Eng. Match the indent to the level you mean. - Putting a value on a parent that also has children. Let the leaves carry the numbers so the parent is their sum and not a second, conflicting size.
- Mixing units in one tree. A headcount leaf next to a dollar leaf shares one area scale. Split them.
- A deep tree of tiny leaves. Labels vanish. Keep two or three levels, and group the tail.
Where to go next
The AI treemap generator will nest a budget from a short outline. Check the indents in the editor before you trust the areas, and the cheat sheet has the leaf line. The budget treemap template is a larger allocation if this three-leaf example is too small to reuse.
Parents are sums
A treemap shows parts of a whole. The parent value should be the sum of its children, or you should leave the parent value off and let the children define the size. A parent of 100 with children that sum to 40 looks like a budget that lost money, and a reader will ask where it went.
Names are the line items, not the conclusion. "Cloud" as a parent with "Compute" and "Storage" under it is a budget. "Too expensive" as a leaf is a comment. Put the comment in the prose. The budget treemap template is a department split you can replace with your own numbers. If the data is a trend over months rather than a split of one total, use an XY chart instead.
Round displayed numbers in the prose, and keep the full values in the diagram so the rectangles still match the sheet.
Tips and best practices
- Indentation defines the hierarchy, like a mindmap.
- Only leaves need values; parents sum their children.
- Avoid very deep hierarchies — two or three levels read best.
Generate a treemap with AI
Not sure where to start? Describe what you need and the AI treemap generator writes the Mermaid code for you. Try prompts like:
- “Website bundle size by package”
- “Company headcount by department and team”
- “Time spent per project per month”
Treemap templates
Treemap FAQ
Do parent nodes in a Mermaid treemap need values?
No. Parent sizes are calculated from the sum of their children; only leaf nodes need a value.