React Treemap Chart
A React treemap chart with ApexCharts in AdminKit PRO: values as nested rectangles sized by value, drawn by the ApexChart component.
This component is only available in AdminKit PRO. Learn more.
A treemap shows how a whole splits into parts, and makes the large parts stand out. Each value is a rectangle, with an area proportional to the value.
In AdminKit for React, the ApexChart component draws it with ApexCharts. Chart setup describes the component.
Example
import { ApexChart } from "@/components/plugins/apexcharts";
const cities = [
{ x: "New Delhi", y: 218 },
{ x: "Kolkata", y: 149 },
{ x: "Mumbai", y: 184 },
{ x: "Ahmedabad", y: 55 },
{ x: "Bengaluru", y: 84 },
{ x: "Pune", y: 31 },
{ x: "Chennai", y: 70 },
{ x: "Jaipur", y: 30 },
{ x: "Surat", y: 44 },
{ x: "Hyderabad", y: 68 },
{ x: "Lucknow", y: 28 },
{ x: "Indore", y: 19 },
{ x: "Kanpur", y: 29 },
];
export function CitiesTreemap() {
return (
<div className="position-relative" style={{ minHeight: 365 }}>
<ApexChart
options={() => ({
series: [{ data: cities }],
legend: { show: false },
chart: { height: 350, type: "treemap" },
title: { text: "Basic Treemap" },
})}
/>
</div>
);
}The rectangles are in the primary color, the first default color of the wrapper, in lighter and darker shades by value.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
options | (theme: Theme) => ApexOptions | The ApexCharts options, with series and chart.type. Called again with the new colors when the color mode changes |
Data and colors
Each rectangle is { x, y }: x is its label and y its value, which sets its area.
plotOptions.treemap sets the colors:
distributed: truegives each rectangle the next color ofcolorsinstead of shades of one color.enableShades: falseturns the shades off, so all rectangles of a series have the same color.- With several series, each series is a group of rectangles in its own color. Then
legend.showcan stay on to name the groups.
<ApexChart
options={(theme) => ({
series: [{ data: cities }],
legend: { show: false },
chart: { height: 350, type: "treemap" },
colors: [
theme.primary,
theme.success,
theme.warning,
theme.danger,
theme.info,
],
plotOptions: { treemap: { distributed: true, enableShades: false } },
})}
/>Accessibility
- Each rectangle shows its label as a data label, so you can read it without the tooltip. Small rectangles may be too small for it. The exact values show in the tooltip on hover only, so give them in a table too when they matter.
- Area is hard to compare by eye. Sort the same data in a list or table when the ranking matters.
role="figure"and anaria-labelonApexChartname the chart: other props go to its<div>.
Related
- Next.js treemap chart: the same chart in AdminKit for Next.js
- Bootstrap 5 treemap chart: the ApexCharts example of the HTML version
- Chart setup: the
ApexChart,ChartJsandVectorMapcomponents - React heatmap chart: values as colors in a grid
- ApexCharts demo: the line, area, bar, column, pie, heatmap, mixed and candlestick charts of the demo
Last updated on
Timeline chartPro
A React timeline chart with ApexCharts in AdminKit PRO: tasks as horizontal bars from a start to an end date, drawn as a rangeBar chart.
Lucide Icons
React Lucide icons in AdminKit: import each icon as a component, size it with a class, color it with text utilities and give icon-only buttons a label.