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.

Loading Demo...

#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.

Loading Demo...

#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.

Loading Demo...

#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.

Loading Demo...

#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.

Loading Demo...

#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.

Loading Demo...

#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.

Loading Demo...

#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.

Loading Demo...

#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.

Loading Demo...

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.

Loading Demo...

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.

Loading Demo...

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.

Loading Demo...

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.

Loading Demo...

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.

PropTypeDefaultDescription
dataT[]-Data array. Mutually exclusive with ChartTreemapGroup / ChartItem children
categoryFieldstring'category'Field name for the cell display label
valueFieldstring'value'Field name for the numeric value that determines cell area
nodeIdstring-Field name holding each item's own unique ID, used with parentField for flat adjacency-list hierarchy
parentFieldstring-Field name holding each item's parent ID, used with nodeId for flat adjacency-list hierarchy
coloraccessor → FillValue-Cell fill color. Static color, array (cycles by group index), field name, or callback. Accepts hex, RGB, and gradient objects
opacityaccessor → number1Cell fill opacity in [0, 1]. Per-cell via array/callback/field-name
colorValueFieldstring-Field name for the numeric value used to map cells to a color gradient
colorRangestring[]-Multi-stop color array. Without colorScale, breakpoints are auto-computed from data min/max
colorScalenumber[]-Explicit breakpoints for color interpolation matching each colorRange stop
borderColoraccessor → FillValue-Cell border stroke color
borderStrokeWidthaccessor → number-Cell border stroke width (px)
borderDashaccessor → number[]-Cell border dash pattern. Also accepts named shortcuts
borderDashOffsetaccessor → number0Cell border dash phase offset
labelColoraccessor → FillValueauto-contrastLabel text color. Per-cell via array/callback/field-name
hoverColoraccessor → FillValue-Per-cell fill color on hover. Short-circuits the global ChartHover.brightness cascade
hoverBorderColoraccessor → FillValue-Per-cell border color on hover
layout'squarify' | 'slice' | 'dice' | 'sliceDice''squarify'Tiling algorithm
spacingnumber2Gap between sibling cells in pixels
groupPaddingnumber3Padding around parent container regions (px)
levelsTreemapLevelConfig[]-Per-depth styling overrides. See TreemapLevelConfig below
borderRadiusnumber2Corner radius of treemap cells (px)
labelMinSizenumber30Minimum cell dimension (px) to show its label
showGroupLabelbooleantrue when parentField is setShow parent header labels
groupLabelHeightnumber18Height of parent header labels (px)
drilldownbooleanfalseEnable 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
rootLabelstring-Top-level breadcrumb label, e.g. 'All' or 'S&P 500'
interactByLeafbooleantrueIn 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
namestring-Dataset label, used in tooltip
idstringautoUnique dataset identifier
ordernumberautoRendering z-order

#TreemapLevelConfig

Each entry in levels styles all cells at a given depth.

FieldTypeDescription
depthnumberDepth this config applies to (0 = top-level groups)
layout'squarify' | 'slice' | 'dice' | 'sliceDice'Layout algorithm for this depth
spacingnumberGap between cells at this depth (px)
borderStrokeWidthnumberCell border width at this depth (px)
borderColorstringCell border color at this depth
showHeaderbooleanShow the group header strip at this depth
headerHeightnumberHeader strip height at this depth (px)
colorByPointbooleanColor 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.

FieldTypeDescription
datumTOriginal data row
valuenumber | nullResolved numeric value (cell area)
indexnumberCell position within the dataset
seriesIndexnumberOrder of this dataset within the chart
seriesIdstringDataset id
categorystring?Resolved cell label, when applicable

#Color Resolution Priority

PriorityConditionBehavior
1colorValueField + colorScale + colorRangeExplicit gradient with custom breakpoints
2colorValueField + colorRangeGradient with breakpoints auto-computed from data min/max
3color (static or array)Static color or palette cycling by group index
4None setDefault group color palette

#TreemapCellContext

Passed to the renderContent callback for each cell.

FieldTypeDescription
dataTOriginal data item
indexnumberData array index
labelstringPrimary label text
secondaryLabelstring | undefinedSecondary label text
valuenumberNumeric value that determines cell area
colorstringResolved fill color
xnumberCell x position in pixels
ynumberCell y position in pixels
widthnumberCell width in pixels
heightnumberCell height in pixels
nodeIdstring | undefinedNode ID for hierarchical data
parentIdstring | undefinedParent node ID for hierarchical data
hasChildrenboolean | undefinedWhether this cell can be drilled into
depthnumberDepth in the hierarchy, 0 = root level
drilldownParentIdstring | nullThe parent ID currently drilled into, null = root level
ctxCanvasRenderingContext2D | undefinedCanvas 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.

PropTypeDefaultDescription
separatorstring' / '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.

PropTypeDescription
labelstringGroup header label
colorstringGroup color, used for the header and child cell tinting
opacitynumberGroup opacity (0–1)

#ChartItem

Use ChartItem as children of ChartTreemapGroup or directly inside ChartTreemap for inline leaf cell definitions.

PropTypeDescription
valuenumberCell area value
categorystringCell display label
colorstringOverride color for this cell
opacitynumberCell opacity (0–1)