Charts

Treemap

Visualize hierarchical data as nested rectangles

Treemap displays hierarchical data as nested rectangles where the area of each rectangle is proportional to its value.

Simple Treemap

A basic treemap with nested data groups. Each group gets a distinct color from the colorPanel.

Custom Content

Use the #content slot to fully customize how each node is rendered. The slot receives coordinates, dimensions, name, value, and fill color.

Nest Mode

Set type="nest" for interactive drill-down. Click a group to zoom into its children. A breadcrumb trail appears for navigating back.

Treemap props

PropTypeDefaultDescription
dataArrayrequiredHierarchical data with optional children arrays
dataKeystring'value'Property name for numeric values
nameKeystring'name'Property name for node labels
widthnumberrequiredChart width in pixels
heightnumberrequiredChart height in pixels
aspectRationumber4/3Target rectangle aspect ratio for squarify layout
type'flat' | 'nest''flat'flat shows all leaves; nest enables drill-down
fillstring'#808080'Default fill color
strokestring'#fff'Rectangle border color
colorPanelstring[]8-color defaultColor palette assigned by top-level group
isAnimationActivebooleantrueEnable entrance animation
transitionAnimationOptions{ duration: 0.8, ease: 'easeOut' }Animation timing (motion-v)
onClick(node, event) => voidClick event handler
onMouseEnter(node, event) => voidMouse enter handler; activates tooltip at node center
onMouseLeave(node, event) => voidMouse leave handler; clears tooltip hover state

Slots

SlotPropsDescription
#contentTreemapContentSlotPropsCustom node rendering. Receives { x, y, width, height, depth, name, value, index, fill, stroke, payload, root, color }.
defaultPlace <Tooltip> or other child components here.

Data structure

const data = [
  {
    name: 'Group A',
    children: [
      { name: 'Item 1', value: 100 },
      { name: 'Item 2', value: 200 },
    ],
  },
  {
    name: 'Group B',
    children: [
      { name: 'Item 3', value: 300 },
    ],
  },
]

Leaf nodes must have a numeric value (or whatever dataKey specifies). Parent nodes derive their value by summing all descendants.

Copyright © 2026