Components · Tables

Heat map

A grid of cells coloured by value, for spotting hot and cold combinations.

Open in playground

Preview

Customers by industry and plan

CustomersStarterGrowthEnterprise
Health13322491
Media43822019
Retail46524531
Tech24639566

Usage

tsx
import { ChartsProvider, HeatMap, dimension, measure, results } from 'em-kit';

const industry = dimension({ name: 'industry', title: 'Industry' });
const plan = dimension({ name: 'plan', title: 'Plan' });
const customers = measure({ name: 'customers', title: 'Customers' });

export const Example = () => (
  <ChartsProvider>
    <div style={{ height: 320 }}>
      <HeatMap
        title="Customers by industry and plan"
        rowDimension={industry}
        columnDimension={plan}
        measure={customers}
        results={results(rows)}
      />
    </div>
  </ChartsProvider>
);

const rows = [
  { plan: 'Starter', industry: 'Health', customers: 133 },
  { plan: 'Growth', industry: 'Health', customers: 224 },
  { plan: 'Enterprise', industry: 'Health', customers: 91 },
  { plan: 'Starter', industry: 'Media', customers: 438 },
  { plan: 'Growth', industry: 'Media', customers: 220 },
  { plan: 'Enterprise', industry: 'Media', customers: 19 },
  { plan: 'Starter', industry: 'Retail', customers: 465 },
  { plan: 'Growth', industry: 'Retail', customers: 245 },
  { plan: 'Enterprise', industry: 'Retail', customers: 31 },
  { plan: 'Starter', industry: 'Tech', customers: 246 },
  { plan: 'Growth', industry: 'Tech', customers: 395 },
  { plan: 'Enterprise', industry: 'Tech', customers: 66 },
];

Install with npm install em-kit. Needs <ChartsProvider> once and a parent with a height: Quick start.

Examples

Custom colour scale

Your own cold, middle and hot colours. minColor, midColor and maxColor; the cell text switches between dark and light for contrast.

tsxDiffers from Usage
Show full code (37 lines)
import { ChartsProvider, HeatMap, dimension, measure, results } from 'em-kit';

const industry = dimension({ name: 'industry', title: 'Industry' });
const plan = dimension({ name: 'plan', title: 'Plan' });
const customers = measure({ name: 'customers', title: 'Customers' });

export const Example = () => (
  <ChartsProvider>
    <div style={{ height: 320 }}>
      <HeatMap
        title="Customers by industry and plan"
        rowDimension={industry}
        columnDimension={plan}
        measure={customers}
        results={results(rows)}
        minColor="#ecfeff"
        midColor="#22d3ee"
        maxColor="#155e75"
      />
    </div>
  </ChartsProvider>
);

const rows = [
  { plan: 'Starter', industry: 'Health', customers: 133 },
  { plan: 'Growth', industry: 'Health', customers: 224 },
  { plan: 'Enterprise', industry: 'Health', customers: 91 },
  { plan: 'Starter', industry: 'Media', customers: 438 },
  { plan: 'Growth', industry: 'Media', customers: 220 },
  { plan: 'Enterprise', industry: 'Media', customers: 19 },
  { plan: 'Starter', industry: 'Retail', customers: 465 },
  { plan: 'Growth', industry: 'Retail', customers: 245 },
  { plan: 'Enterprise', industry: 'Retail', customers: 31 },
  { plan: 'Starter', industry: 'Tech', customers: 246 },
  { plan: 'Growth', industry: 'Tech', customers: 395 },
  { plan: 'Enterprise', industry: 'Tech', customers: 66 },
];
<HeatMap
  title="Customers by industry and plan"
  rowDimension={industry}
  columnDimension={plan}
  measure={customers}
  results={results(rows)}
  minColor="#ecfeff"
  midColor="#22d3ee"
  maxColor="#155e75"
/>

Thresholds

Everything in the bottom fifth of the range fully cold and the top fifth fully hot, so outliers don’t wash out the rest. Thresholds take a raw value or a percentage of the range: minThreshold: '20%', maxThreshold: '80%'.

tsxDiffers from Usage
Show full code (36 lines)
import { ChartsProvider, HeatMap, dimension, measure, results } from 'em-kit';

const industry = dimension({ name: 'industry', title: 'Industry' });
const plan = dimension({ name: 'plan', title: 'Plan' });
const customers = measure({ name: 'customers', title: 'Customers' });

export const Example = () => (
  <ChartsProvider>
    <div style={{ height: 320 }}>
      <HeatMap
        title="Customers by industry and plan"
        rowDimension={industry}
        columnDimension={plan}
        measure={customers}
        results={results(rows)}
        minThreshold="20%"
        maxThreshold="80%"
      />
    </div>
  </ChartsProvider>
);

const rows = [
  { plan: 'Starter', industry: 'Health', customers: 133 },
  { plan: 'Growth', industry: 'Health', customers: 224 },
  { plan: 'Enterprise', industry: 'Health', customers: 91 },
  { plan: 'Starter', industry: 'Media', customers: 438 },
  { plan: 'Growth', industry: 'Media', customers: 220 },
  { plan: 'Enterprise', industry: 'Media', customers: 19 },
  { plan: 'Starter', industry: 'Retail', customers: 465 },
  { plan: 'Growth', industry: 'Retail', customers: 245 },
  { plan: 'Enterprise', industry: 'Retail', customers: 31 },
  { plan: 'Starter', industry: 'Tech', customers: 246 },
  { plan: 'Growth', industry: 'Tech', customers: 395 },
  { plan: 'Enterprise', industry: 'Tech', customers: 66 },
];
const industry = dimension({ name: 'industry', title: 'Industry' });
const plan = dimension({ name: 'plan', title: 'Plan' });
const customers = measure({ name: 'customers', title: 'Customers' });

<HeatMap
  title="Customers by industry and plan"
  rowDimension={industry}
  columnDimension={plan}
  measure={customers}
  results={results(rows)}
  minThreshold="20%"
  maxThreshold="80%"
/>

Colours only

No numbers in the cells, for a compact pattern view; the values stay in the exports.

tsxDiffers from Usage
Show full code (35 lines)
import { ChartsProvider, HeatMap, dimension, measure, results } from 'em-kit';

const industry = dimension({ name: 'industry', title: 'Industry' });
const plan = dimension({ name: 'plan', title: 'Plan' });
const customers = measure({ name: 'customers', title: 'Customers' });

export const Example = () => (
  <ChartsProvider>
    <div style={{ height: 320 }}>
      <HeatMap
        title="Customers by industry and plan"
        rowDimension={industry}
        columnDimension={plan}
        measure={customers}
        results={results(rows)}
        showValues={false}
      />
    </div>
  </ChartsProvider>
);

const rows = [
  { plan: 'Starter', industry: 'Health', customers: 133 },
  { plan: 'Growth', industry: 'Health', customers: 224 },
  { plan: 'Enterprise', industry: 'Health', customers: 91 },
  { plan: 'Starter', industry: 'Media', customers: 438 },
  { plan: 'Growth', industry: 'Media', customers: 220 },
  { plan: 'Enterprise', industry: 'Media', customers: 19 },
  { plan: 'Starter', industry: 'Retail', customers: 465 },
  { plan: 'Growth', industry: 'Retail', customers: 245 },
  { plan: 'Enterprise', industry: 'Retail', customers: 31 },
  { plan: 'Starter', industry: 'Tech', customers: 246 },
  { plan: 'Growth', industry: 'Tech', customers: 395 },
  { plan: 'Enterprise', industry: 'Tech', customers: 66 },
];
const industry = dimension({ name: 'industry', title: 'Industry' });
const plan = dimension({ name: 'plan', title: 'Plan' });
const customers = measure({ name: 'customers', title: 'Customers' });

<HeatMap
  title="Customers by industry and plan"
  rowDimension={industry}
  columnDimension={plan}
  measure={customers}
  results={results(rows)}
  showValues={false}
/>

Props

PropTypeDefaultDescription
rowDimensionrequiredDimensionThe dimension down the side of the grid.
columnDimensionrequiredDimensionThe dimension across the top of the grid.
measurerequiredMeasureThe number behind each cell’s colour and label.
resultsrequiredDataResponseYour query’s state: { isLoading, data, error }, where data is your rows. results(rows) builds it from an array.
columnWidthnumberA fixed width for the value columns, in pixels.
displayNullAsstringText shown where a value is null, for example "–".
firstColumnWidthnumberA fixed width for the row-label column, in pixels.
maxColorstringColour of the highest values.
maxThresholdstringValues at this get maxColor; values above it darken further. A number as a string, or a percentage of the range such as "80%".
midColorstringColour of the values in the middle of the range.
minColorstringColour of the lowest values.
minThresholdstringValues at this get minColor; values below it fade further towards white. A number as a string ("100"), or a percentage of the range such as "20%".
showValuesbooleantruePrint the value in each cell.
onCellClicked(args: HeatMapOptionsClickArg) => voidCalled with the clicked cell’s row and column values.HeatMapOptionsClickArg = { rowDimensionValue: string | undefined; rowDimensionTimeRange: TimeRange; columnDimensionValue: string | undefined; columnDimensionTimeRange: TimeRange; }
componentNamestringA name for this component, included in the interaction events it dispatches on the DOM, for your analytics.
trackingIdstringAn id included in the same events, to tell two instances apart.
titlestringThe card’s title. A "key|fallback" string is looked up in your translations.
descriptionstringSmaller text under the title. Translates like title.
tooltipstringText for an info icon beside the title.
hideMenubooleanfalseHide the card’s header: the title, description and menu.
menuOptions("csv" | "xlsx" | "png" | "maximize")[]["csv", "xlsx", "png", "maximize"]Which entries the card menu offers. Pass [] for none.

A blank default means the prop is unset unless you pass it.

TypeDefinition
TimeRange{ from: Date | undefined; to: Date | undefined; relativeTimeString?: string; } | undefinedWhat a click’s TimeRange holds: Events.

Field options

HeatMap reads only the common options in a field’s inputs.

Keyboard

KeyWhereWhat it does
Tab, Shift + TabGridMoves from cell to cell: every cell takes focus.
Enter or SpaceCellCalls onCellClicked with the cell’s row and column values, if you passed it.

The card menu’s keys, and what is still missing, are in Accessibility.