AG Studio Launch Week 🚀🚀🚀 28 Sep - 2 Oct 2026 🚀🚀🚀 Join now

JavaScript ChartsTreemap Series

Version 14.2.0
Enterprise

A Treemap Series is used to render hierarchical data structures or trees. Each node in the tree is represented by a rectangle, with the area of the rectangle representing the value.

Simple Treemap Copy Link

The Treemap Series is designed to display a single series and is created using the treemap series type.

{
    series: [
        {
            type: 'treemap',
            labelKey: 'title',
        },
    ],
}

The data passed in should be an array of nodes, with each node optionally containing children.

let data = [
    {
        title: 'Pensions',
        children: [
            { title: 'Sickness and disability', total: 61.2, change: 8.7 },
            { title: 'Old age', total: 141.8, change: 17.9 },
            { title: 'Survivors', total: 1.4, change: 0 },
        ],
    },
    {
        title: 'Health Care',
        // ...
    },
    // ...
];

The labelKey defines what will appear as the title for each tile.

Sizing Copy Link

By default, each leaf node's rectangle will have approximately the same area.

However, the Treemap Series is best suited to providing size values to provide relative sizing between these rectangles.

The sizeKey can be used to provide a numeric value to adjust the relative sizing. Additionally, the optional sizeName property can be set to set the title that appears next to the value in tooltips.

{
    series: [
        {
            type: 'treemap',
            labelKey: 'title',
            sizeKey: 'total',
            sizeName: 'Total',
        },
    ],
}

Only the sizes of leaf nodes will be accounted for when computing the relative sizes. When sizes are used, the nodes will be re-ordered so larger nodes appear towards the top left corner.

Colour Scale Copy Link

Use colorScale to control how colorKey values map to colours.

{
    series: [
        {
            type: 'treemap',
            labelKey: 'title',
            colorKey: 'change',
            colorName: 'Change',
            colorScale: {
                mode: 'discrete',
                fills: [
                    { color: 'tomato', stop: -0.1, name: 'Decline' },
                    { color: 'gold', stop: 0.1, name: 'Flat' },
                    { color: 'seagreen', name: 'Growth' },
                ],
            },
        },
    ],
}

In this example:

  • Use the toggle to switch between discrete mode with named stops shown in a category legend, and a continuous gradient shown in a gradient legend.

See the Colour Scale page for the full range of colour scale options including discrete mode, named stops, fixed domains, missing data, and gradient legend customisation.

Other Colours Copy Link

It's possible to override the default colours, or the colours on a group or tile basis.

{
    series: [
        {
            type: 'treemap',
            labelKey: 'title',
            sizeKey: 'total',
            sizeName: 'Total',
            fills: ['#E64A19', '#F57C00', '#FFA000', '#FBC02D', '#AFB42B', '#689F38', '#388E3C', '#00796B', '#0097A7', '#0288D1'],
            strokes: ['#D84315', '#EF6C00', '#FF8F00', '#F9A825', '#9E9D24', '#558B2F', '#2E7D32', '#00695C', '#00838F', '#0277BD'],
        },
    ],
}

In this configuration:

  • fills and strokes are an array of colours to use for the fills and strokes, where node receives the colour indexed by the index of its root node

When colorScale.fills is used, the fills and strokes arrays are ignored.

Labels Copy Link

Both the labels for leaf and non-leaf nodes can be customised.

For leaf nodes only, they can contain secondary labels, and their labels can also be shrunk to fit in the available space.

Labels can be customised through the group and tile properties for non-leaf nodes and leaf nodes, respectively.

{
    series: [
        {
            type: 'treemap',
            labelKey: 'title',
            secondaryLabelKey: 'total',
            sizeKey: 'total',
            sizeName: 'Total',
            group: {
                label: {
                    fontSize: 18,
                    spacing: 2,
                },
            },
            tile: {
                label: {
                    fontSize: 24,
                    minimumFontSize: 9,
                    spacing: 8,
                },
                secondaryLabel: {
                    formatter: (params) =>${params.value.toFixed(1)}bn`,
                },
            },
        },
    ],
}

In this configuration:

  • fontSize sets the size of the font
  • minimumFontSize will enable the font size to shrink down to the given value if there is not enough space (tiles only)
  • spacing controls the amount of space below a label
  • padding adds space between the edge of a group or tile and its contents
  • formatter allows customising the value of a label using a function

Layout Copy Link

Various spacing values can be adjusted to tweak the layout of the chart.

{
    series: [
        {
            type: 'treemap',
            labelKey: 'title',
            sizeKey: 'total',
            sizeName: 'Total',
            group: {
                padding: 12,
                gap: 5,
            },
            tile: {
                padding: 10,
                gap: 2,
            },
        },
    ],
}

In this configuration:

  • group.padding adjusts the padding between the edge of the group, its title, and the inner nodes
  • group.gap adjusts the gap between adjacent tiles where one or more nodes in the parent node are group nodes
  • tile.padding adjusts the padding between the edge of the tile and its labels
  • tile.gap adjusts the gap between adjacent tiles where all nodes in the parent node are leaf nodes

Hierarchy Levels Copy Link

Treemap Series supports multiple levels within a hierarchy.

Highlighting Copy Link

Treemaps leaf tiles are configured via tile.highlight, while group rectangles use group.highlight.

The leaf tiles support the following states:

  • highlightedItem – styles applied to the hovered tile.
  • unhighlightedItem – styles applied to other nodes within the same branch.
  • highlightedBranch – styles inherited by every node that shares the hovered root.
  • unhighlightedBranch – styles applied to nodes in other branches.

The groups support the following states:

  • highlightedItem – styles applied to the hovered group.
  • unhighlightedItem – styles applied to other groups.

When a group is hovered, its fillOpacity and strokeOpacity styles are inherited by its child leaf tiles.

{
    series: [
        {
            type: 'treemap',
            labelKey: 'title',
            sizeKey: 'total',
            group: {
                highlight: {
                    highlightedItem: { stroke: 'lightgreen', strokeWidth: 4 },
                    unhighlightedItem: { opacity: 0.1 },
                },
            },
            tile: {
                highlight: {
                    highlightedItem: { stroke: 'green' },
                    highlightedBranch: { strokeWidth: 2 },
                    unhighlightedBranch: { fill: 'grey' },
                },
            },
        },
    ],
}

In this configuration:

  • group.highlight only affects the group rectangles.
  • tile.highlight controls the tiles themselves. When a group is hovered, only the fillOpacity and strokeOpacity styles are inherited by its tiles.
  • Providing fill/stroke overrides allows highlight colours to take precedence over colour scales.

Treemap Chart Examples Copy Link

See more Treemap Chart examples in the AG Charts Gallery.

API Reference Copy Link

Properties available on the AgTreemapSeriesOptions interface.

type required 'treemap'
Configuration for the Treemap Series.
id string default: auto-generated value
Primary identifier for the series. This is provided as `seriesId` in user callbacks to differentiate multiple series. Auto-generated ids are subject to future change without warning, if your callbacks need to vary behaviour by series please supply your own unique `id` value.
context ContextDefault
Context object to use in callbacks.
data DatumDefault[]
The data to use when rendering the series. If this is not supplied, data must be set on the chart instead.
visible boolean
Whether to display the series.
cursor string
The cursor to use for hovered markers. This config is identical to the CSS `cursor` property.
nodeClickRange InteractionRange
Range from a node that a click triggers the listener.
listeners AgSeriesListeners
A map of event names to event listeners.
labelKey string
The name of the node key containing the label.
secondaryLabelKey string
The name of the node key containing a secondary label.
childrenKey string
The name of the node key containing the children. Defaults to `children`.
sizeKey string
The name of the node key containing the size value.
colorKey string
The name of the node key containing the colour value. This value (along with `colorScale` config) will be used to determine the tile colour.
sizeName string
A human-readable description of the size values. If supplied, this will be shown in the default tooltip and passed to the tooltip renderer as one of the parameters.
colorName string
A human-readable description of the colour values. If supplied, this will be shown in the default tooltip and passed to the tooltip renderer as one of the parameters.
fills AgColorType[]
The colours to cycle through for the fills of the groups and tiles. An array of colour strings, or fill objects for gradients, patterns, or images.
strokes CssColor[]
The colours to cycle through for the strokes of the groups and tiles.
colorScale AgColorScale
Configuration for colour scale with fills, domain, and mode.
group AgTreemapSeriesGroupOptions
Options for group nodes (i.e. nodes WITH children).
tile AgTreemapSeriesTileOptions
Options for leaf nodes (i.e. nodes WITHOUT children).
tooltip AgSeriesTooltip
Series-specific tooltip configuration.
itemStyler Styler
A callback function for adjusting the styles of a particular tile based on the input parameters.