Charts - Treemap
Nested rectangles sized by value, with hierarchy, drilldown, custom content, and multiple layout algorithms.
#Usage
import { ChartBreadcrumb, ChartCanvas, ChartCaption, ChartExportMenu, ChartHover, ChartItem, ChartSvg, ChartTitle, ChartTooltip, ChartTreemap, ChartTreemapGroup } from '@primeui/vue-chart';<ChartSvg>
<ChartTreemap :data="data" category-field="categoryField" value-field="valueField" />
</ChartSvg>Treemaps show hierarchical data as nested rectangles sized by value, good for part-to-whole comparisons with many categories. Cell area scales proportionally to each value. Pass a flat array with parentField and a unique node identifier to define drilldown-enabled hierarchy.
#Basic
Set categoryField and valueField to map data fields. Cell area scales proportionally to each value.
#Colors
Pass an array to color to assign a palette to cells; colors cycle by index across items or groups. Pass a static value to color to apply a single color to all cells.
#Color Range
Set colorValueField to a numeric field to map cell colors to a gradient. Set colorRange to define the color stops; breakpoints are auto-computed from the data min/max. Set colorScale alongside colorRange to define explicit breakpoints, useful for diverging scales where negative, neutral, and positive values need stable stops.
#Hierarchy
Set nodeId to the field name holding each item's own unique ID, and parentField to the field name holding its parent's ID, the same pattern as a SQL adjacency list. The treemap builds the full hierarchy by matching IDs to parent references. Parent nodes with a null or missing parent value become top-level containers.
#Drilldown
Set drilldown to enable click-to-drill navigation. Clicking a parent cell zooms into its children. Add ChartBreadcrumb to display a navigation trail; click any crumb to drill back up. Set rootLabel to name the top-level breadcrumb entry.
Set drilldownMode="flat" to render parent cells as regular solid cells where clicking drills in. The default "nested" mode shows parent headers with children visible inside.
#Layout
Set layout to control the tiling algorithm. squarify (default) minimizes aspect ratio; cells are as square as possible. slice creates horizontal strips, dice creates vertical strips, and sliceDice alternates between them by depth level.
#Labels
Set labelMinSize to hide labels on cells too small to fit text. Use showGroupLabel and groupLabelHeight to control parent header label visibility and height.
#Custom Content
Set renderContent to replace default cell labels with fully custom content. The callback receives the cell's position, dimensions, value, color, and label fields. In SVG mode return a VNode. In Canvas mode the context is pre-clipped to the cell bounds; draw directly and return null.
#Declarative
Define cells inline using ChartTreemapGroup and ChartItem children instead of a data array. ChartTreemapGroup creates a parent container; set label and color. Nest ChartItem children inside each group to define the leaf cells. This pattern maps directly to the group + drilldown hierarchy; each ChartTreemapGroup becomes a drillable parent when drilldown is set on ChartTreemap.
#Title & Caption
Add ChartTitle to display a title above the chart and ChartCaption for a descriptive line beneath it. Adding both reduces the available chart area.
For full configuration see Title & Caption.
#Hover
ChartHover brightens the hovered cell while the rest stay at normal opacity. Set brightness to control the lightening factor, or set dimOpacity below 1 when you intentionally want non-hovered cells to fade.
For full configuration see Hover.
#Tooltip
Add ChartTooltip to show cell details on hover. The tooltip displays the label and value for the hovered cell.
For full configuration see Tooltip.
#Legend
Add ChartColorLegend to map cell colors to a value scale. Set colorValueField to color cells by a metric separate from their size, and pass matching colorScale and colorRange stops. The legend renders a gradient bar; set position to top, bottom, left, or right.
For full configuration see Legend.
#Data Labels
Add ChartDataLabels to display a value line below the leaf cell name. By default the value line shows the plain value. Set display to value, percentage, or both to switch the content, where the percentage is each leaf's share of the visible leaf total. Set formatter to build custom text; the callback receives the value, percentage, name, and row datum, so a sibling field such as a change value can drive the line. Set color to style the value line, while labelColor on ChartTreemap still colors the cell name.
For full configuration see Data Labels.
#Animation
Pass the chart-root animation prop (<ChartSvg> / <ChartCanvas>) to control entrance and update transitions. Cells grow from their center position on entrance. Drilldown transitions use a zoom animation.
For full configuration see Animation.
#Export
Add ChartExportMenu to let users download the chart as PNG, SVG, or PDF.
See Export for format options and programmatic export.
#Responsive
See Responsive for container sizing, aspect ratio, and breakpoint configuration.
#Accessibility
See Accessibility for ARIA labels, keyboard navigation, and screen reader support.
#API
#ChartTreemap
Visual styling props with type accessor → R accept a static value, a per-cell array, a field name (keyof T), or a callback (ctx: ItemContext<T>) => R | undefined. Color-family arrays cycle modulo length; other accessor arrays clip and fall back to the series default.
| Prop | Type | Default | Description |
|---|---|---|---|
data | T[] | - | Data array. Mutually exclusive with ChartTreemapGroup / ChartItem children |
categoryField | string | 'category' | Field name for the cell display label |
valueField | string | 'value' | Field name for the numeric value that determines cell area |
nodeId | string | - | Field name holding each item's own unique ID, used with parentField for flat adjacency-list hierarchy |
parentField | string | - | Field name holding each item's parent ID, used with nodeId for flat adjacency-list hierarchy |
color | accessor → FillValue | - | Cell fill color. Static color, array (cycles by group index), field name, or callback. Accepts hex, RGB, and gradient objects |
opacity | accessor → number | 1 | Cell fill opacity in [0, 1]. Per-cell via array/callback/field-name |
colorValueField | string | - | Field name for the numeric value used to map cells to a color gradient |
colorRange | string[] | - | Multi-stop color array. Without colorScale, breakpoints are auto-computed from data min/max |
colorScale | number[] | - | Explicit breakpoints for color interpolation matching each colorRange stop |
borderColor | accessor → FillValue | - | Cell border stroke color |
borderStrokeWidth | accessor → number | - | Cell border stroke width (px) |
borderDash | accessor → number[] | - | Cell border dash pattern. Also accepts named shortcuts |
borderDashOffset | accessor → number | 0 | Cell border dash phase offset |
labelColor | accessor → FillValue | auto-contrast | Label text color. Per-cell via array/callback/field-name |
hoverColor | accessor → FillValue | - | Per-cell fill color on hover. Short-circuits the global ChartHover.brightness cascade |
hoverBorderColor | accessor → FillValue | - | Per-cell border color on hover |
layout | 'squarify' | 'slice' | 'dice' | 'sliceDice' | 'squarify' | Tiling algorithm |
spacing | number | 2 | Gap between sibling cells in pixels |
groupPadding | number | 3 | Padding around parent container regions (px) |
levels | TreemapLevelConfig[] | - | Per-depth styling overrides. See TreemapLevelConfig below |
borderRadius | number | 2 | Corner radius of treemap cells (px) |
labelMinSize | number | 30 | Minimum cell dimension (px) to show its label |
showGroupLabel | boolean | true when parentField is set | Show parent header labels |
groupLabelHeight | number | 18 | Height of parent header labels (px) |
drilldown | boolean | false | Enable click-to-drill navigation into parent groups |
drilldownMode | 'nested' | 'flat' | 'nested' | nested = parent headers visible with children inside. flat = parents as solid cells, click to drill |
rootLabel | string | - | Top-level breadcrumb label, e.g. 'All' or 'S&P 500' |
interactByLeaf | boolean | true | In nested mode: hovering a leaf's label shows leaf info, hovering its background shows parent info |
renderContent | (context: TreemapCellContext) => unknown | - | Custom cell content renderer. SVG: return a VNode. Canvas: context is pre-clipped to cell bounds; draw directly and return null |
name | string | - | Dataset label, used in tooltip |
id | string | auto | Unique dataset identifier |
order | number | auto | Rendering z-order |
#TreemapLevelConfig
Each entry in levels styles all cells at a given depth.
| Field | Type | Description |
|---|---|---|
depth | number | Depth this config applies to (0 = top-level groups) |
layout | 'squarify' | 'slice' | 'dice' | 'sliceDice' | Layout algorithm for this depth |
spacing | number | Gap between cells at this depth (px) |
borderStrokeWidth | number | Cell border width at this depth (px) |
borderColor | string | Cell border color at this depth |
showHeader | boolean | Show the group header strip at this depth |
headerHeight | number | Header strip height at this depth (px) |
colorByPoint | boolean | Color each cell at this depth individually |
#ItemContext
Passed to every accessor → R callback. Return undefined to fall back to the series-level default for that cell.
| Field | Type | Description |
|---|---|---|
datum | T | Original data row |
value | number | null | Resolved numeric value (cell area) |
index | number | Cell position within the dataset |
seriesIndex | number | Order of this dataset within the chart |
seriesId | string | Dataset id |
category | string? | Resolved cell label, when applicable |
#Color Resolution Priority
| Priority | Condition | Behavior |
|---|---|---|
| 1 | colorValueField + colorScale + colorRange | Explicit gradient with custom breakpoints |
| 2 | colorValueField + colorRange | Gradient with breakpoints auto-computed from data min/max |
| 3 | color (static or array) | Static color or palette cycling by group index |
| 4 | None set | Default group color palette |
#TreemapCellContext
Passed to the renderContent callback for each cell.
| Field | Type | Description |
|---|---|---|
data | T | Original data item |
index | number | Data array index |
label | string | Primary label text |
secondaryLabel | string | undefined | Secondary label text |
value | number | Numeric value that determines cell area |
color | string | Resolved fill color |
x | number | Cell x position in pixels |
y | number | Cell y position in pixels |
width | number | Cell width in pixels |
height | number | Cell height in pixels |
nodeId | string | undefined | Node ID for hierarchical data |
parentId | string | undefined | Parent node ID for hierarchical data |
hasChildren | boolean | undefined | Whether this cell can be drilled into |
depth | number | Depth in the hierarchy, 0 = root level |
drilldownParentId | string | null | The parent ID currently drilled into, null = root level |
ctx | CanvasRenderingContext2D | undefined | Canvas context, present only in Canvas mode |
#ChartBreadcrumb
Add ChartBreadcrumb alongside ChartTreemap when drilldown is enabled to display a navigation trail. Click any crumb to navigate back up the hierarchy. The breadcrumb automatically syncs with the drilldown state and uses rootLabel from ChartTreemap.
| Prop | Type | Default | Description |
|---|---|---|---|
separator | string | ' / ' | Text separator rendered between breadcrumb items |
#ChartTreemapGroup
Use ChartTreemapGroup as children of ChartTreemap for declarative hierarchy definitions. Each group becomes a parent container. Nest ChartItem children inside for leaf cells.
| Prop | Type | Description |
|---|---|---|
label | string | Group header label |
color | string | Group color, used for the header and child cell tinting |
opacity | number | Group opacity (0–1) |
#ChartItem
Use ChartItem as children of ChartTreemapGroup or directly inside ChartTreemap for inline leaf cell definitions.
| Prop | Type | Description |
|---|---|---|
value | number | Cell area value |
category | string | Cell display label |
color | string | Override color for this cell |
opacity | number | Cell opacity (0–1) |