WaffleChart

Part-to-whole grid chart with colored cells

Usage

WaffleChart displays parts of a whole as a grid of cells. Each segment gets a number of cells proportional to its value:

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

function Demo() {
  return <WaffleChart data={data} />;
}

Total

By default, the sum of all values fills the entire grid. Set total to a larger number to leave the remaining cells empty, for example, to display progress towards a goal. A total smaller than the sum of values is ignored. Use emptyColor to change the color of empty cells:

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

function Demo() {
  return (
    <WaffleChart
      data={[{ name: 'Completed', value: 68, color: 'teal' }]}
      total={100}
      emptyColor="var(--mantine-color-teal-light)"
    />
  );
}

Tooltip

Set withTooltip to display the segment name and value on cell hover. Use getTooltipLabel to change the tooltip content:

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

function Demo() {
  return (
    <WaffleChart
      data={data}
      withTooltip
      getTooltipLabel={(cell) => `${cell.name}: ${cell.count} cells`}
    />
  );
}

Legend

Use legendPosition to move the legend or set withLegend={false} to hide it. Like fillDirection, left and right positions do not flip in right-to-left direction:

Legend position
import { WaffleChart } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return <WaffleChart data={data} />;
}

Gap and grid size

Use rows and columns props to change the number of cells, gap and cellRadius to change their spacing and border radius:

Gap
Cell radius
Columns
Rows
import { WaffleChart } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return <WaffleChart data={data} />;
}

Fill direction

fillDirection controls the order in which cells are filled:

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

function Demo() {
  return <WaffleChart data={data} />;
}

Value formatter

Use valueFormatter to format values and the total in the tooltip and in the label announced by screen readers:

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

function Demo() {
  return <WaffleChart data={data} withTooltip valueFormatter={(value) => `${value}%`} />;
}

Accessibility

Set aria-label to summarize the chart in your own words:

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

function Demo() {
  return (
    <WaffleChart
      data={[{ name: 'Occupied', value: 75, color: 'blue' }]}
      total={100}
      aria-label="75 of 100 seats are occupied"
    />
  );
}