Treemap

Treemap chart component

Usage

Treemap is based on the Treemap recharts component. It displays data as rectangles with areas proportional to their values. This example shows which modules contribute most to a JavaScript bundle's size:

JavaScript bundle size

Illustrative build · minified size

import { Treemap } from '@mantine/charts';
import { Stack, Text } from '@mantine/core';
import { data } from './data';

function Demo() {
  return (
    <Stack>
      <div>
        <Text fw={500}>JavaScript bundle size</Text>
        <Text size="sm" c="dimmed">Illustrative build · minified size</Text>
      </div>
      <Treemap data={data} valueFormatter={(value) => `${value} KB`} />
    </Stack>
  );
}

Nested data

Each data item can have a children array. Here, modules are grouped by output chunk and inherit their chunk's color:

Bundle size by chunk

Illustrative build · minified size

import { Treemap } from '@mantine/charts';
import { Stack, Text } from '@mantine/core';
import { data } from './data';

function Demo() {
  return (
    <Stack>
      <div>
        <Text fw={500}>Bundle size by chunk</Text>
        <Text size="sm" c="dimmed">Illustrative build · minified size</Text>
      </div>
      <Treemap data={data} withLegend valueFormatter={(value) => `${value} KB`} />
    </Stack>
  );
}

Legend

Set withLegend to display a legend for top-level nodes. Hover over a legend item to highlight its branch:

import { Treemap } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return <Treemap data={data} valueFormatter={(value) => `${value} KB`} withLegend />;
}

Legend position

The legend is displayed below the chart by default. Set legendProps={{ position: 'top' }} to display it above the chart:

import { Treemap } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return (
    <Treemap
      data={data}
      withLegend
      legendProps={{ position: 'top' }}
      valueFormatter={(value) => `${value} KB`}
    />
  );
}

Node color

color accepts theme colors and any valid CSS color. Nodes without color get a color from a default palette:

import { Treemap } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return <Treemap data={data} valueFormatter={(value) => `${value} KB`} />;
}

Text color

Set textColor to use the same label color on all nodes:

import { Treemap } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return <Treemap data={data} textColor="blue.9" valueFormatter={(value) => `${value} KB`} />;
}

Value formatter

Use valueFormatter to format values in the tooltip:

Sales by product · October 2026

import { Treemap } from '@mantine/charts';
import { Stack, Text } from '@mantine/core';
import { data } from './data';

function Demo() {
  return (
    <Stack>
      <Text fw={500}>Sales by product · October 2026</Text>
      <Treemap
        data={data}
        valueFormatter={(value) =>
          value.toLocaleString('en-US', {
            style: 'currency',
            currency: 'USD',
            maximumFractionDigits: 0,
          })
        }
      />
    </Stack>
  );
}

Data key

By default, node values are read from the value key. Set dataKey to use another key:

import { Treemap } from '@mantine/charts';

const data = [
  { name: 'Charts', sizeKb: 240, color: 'blue.7' },
  { name: 'Editor', sizeKb: 180, color: 'blue.7' },
  { name: 'React DOM', sizeKb: 130, color: 'blue.7' },
];

function Demo() {
  return (
    <Treemap
      data={data}
      dataKey="sizeKb"
      valueFormatter={(value) => `${value} KB`}
    />
  );
}

Node stroke

Use strokeWidth and strokeColor props to change the stroke around nodes:

import { Treemap } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return (
    <Treemap
      data={data}
      strokeColor="gray.3"
      strokeWidth={2}
      valueFormatter={(value) => `${value} KB`}
    />
  );
}

Disable tooltip

To disable the tooltip, set withTooltip={false}:

import { Treemap } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return <Treemap data={data} withTooltip={false} />;
}