Skip to content

3D treemap ​

Treemap tiles raised as high as their value, or as a second value. Good for shares of a whole, when the picture has to strike.

The smallest code that works. change the code, then press Run

In your framework

import { Chart } from 'nervure/react';
import 'nervure/3d';

const spec = {
  type: 'treemap3d',
  data: [
    { name: 'Juice', value: 86 },
    { name: 'Tea', value: 8 },
    { name: 'Cheese', value: 58 },
    { name: 'Soup', value: 6 },
    { name: 'Dates', value: 41 },
    { name: 'Rice', value: 25 },
    { name: 'Olives', value: 27 },
    { name: 'Fruit', value: 67 },
    { name: 'Coffee', value: 7 },
  ],
};

export default function Example() {
  return <Chart spec={spec} style={{ height: 340 }} />;
}

Or import this chart alone: what each import weighs.

Options

Beside the fields shared by every chart (title, format, heading, export…), type treemap3d takes:

/** Treemap tiles raised as high as their value, or as a second value, `height`. */
interface Treemap3DSpec extends Base3D {
  type: 'treemap3d';
  data: (Item & { height?: number })[];
  /** Height of the highest tile, as a share of the longer side: 0.2 by default. */
  height?: number;
  legend?: boolean | LegendOptions;
  onItemClick?: (id: string) => void;
}

interface Base3D extends Base {
  /** Where the eye stands, in degrees: `azimuth` turns around the vertical axis, `elevation` rises from the floor (0) to straight above (90). */
  view?: { azimuth?: number; elevation?: number };
  /** Drag the chart, or focus its turn button and use the arrow keys, to turn the view. Home on the button goes back to `view`. */
  rotate?: boolean;
}

Style it

  • Colours: theme.palette, chart.setColor(name, colour), or --nervure-palette in your CSS. More
  • Marks: [data-series="name"], parts: [data-part="axes"], legend, series. What you change is kept in exports.
  • Movement: animation: false draws at once. More
  • Files: chart.download('png'), svg, csv. More

Close to it