Heatmap for React
A React heatmap chart that colors a category-by-category grid from light to dark, with a tooltip on every cell. Pass data as readonly ChartRow[]: one object per row.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/heatmap.jsonSessions by hour
HeatmapHeatmapTableChartTipMissingValueChartDockHint- +12 more
- +9 more
Activity by hour
24 columns stay readable on a phone: columns shrink to 12px, then the grid scrolls sideways inside the card while the day labels stay put. Focus the grid and use the arrow keys; Home and End jump along a row.
Sessions by hour
Local time, per weekday
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
import { type ChartRow } from "@/components/sheenui/charts/chart-utils";
import { Heatmap } from "@/components/sheenui/charts/heatmap";
import { type HeatmapColumn } from "@/components/sheenui/charts/heatmap/kit";
import { HeatmapTable } from "@/components/sheenui/charts/heatmap/table";
// Package build (after the first npm release, or a packed tarball): import { ChartCard, HeatmapTable, Heatmap, type ChartRow, type HeatmapColumn } from "@sheenui/theme";
const hours: HeatmapColumn[] = Array.from({ length: 24 }, (_, h) => ({ key: `h${h}`, label: String(h).padStart(2, "0") }));
const days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
const data: ChartRow[] = days.map((day, d) => {
const row: ChartRow = { day };
for (let h = 0; h < 24; h++) row[`h${h}`] = Math.round(40 + 600 * Math.exp(-((h - 11) ** 2) / 14) * (d >= 5 ? 0.5 : 1));
return row;
});
export function Example() {
return (
<ChartCard
title="Sessions by hour"
description="Local time"
table={<HeatmapTable data={data} index="day" indexLabel="Day" columns={hours} />}
>
<Heatmap
data={data}
index="day"
columns={hours}
legendLabel="Sessions"
aria-label="Sessions by weekday and hour"
/>
</ChartCard>
);
}Files to copy
12 folders · 26 files · 4 packages
- From
theme/src/ components/charts/{heatmap.tsx, chart-export-menu.tsx, chart-export.ts, chart-figure.tsx, chart-fit.tsx, chart-icons.tsx, chart-parts.tsx, chart-patterns.tsx, chart-tip.tsx, chart-utils.ts}components/charts/chart-parts/components/charts/heatmap/components/drawer/parts/sheet.tsxcomponents/kbd/components/menu/components/skeleton/components/status-icons/hooks/{use-controllable.ts, use-intersection.ts, use-latest.ts, use-media-query.ts, use-preferences.ts}motion/tokens.tslib/{cn.ts, csv.ts, form.ts, glide-highlight.tsx, heading.ts, math.ts, popup-a11y.ts, popup-motion.ts, warn-once.ts}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/heatmap.jsonRegistry item: heatmap. The styles need the Tailwind v4 glass UI setup.- Packages
pnpm add @base-ui/react clsx motion tailwind-merge
Next.js: samples here pass functions (formatters, seriesLegend, a dashboard's load), so put them in a file that starts with "use client".
Cohort retention, classed
Five classes instead of a continuous ramp, with values printed inside the cells that fit them: black or white, whichever contrasts more with that cell. Months that haven't happened yet are missing, so they're hatched.
Cohort retention
Share of each signup cohort still active
import { type ChartRow } from "@/components/sheenui/charts/chart-utils";
import { Heatmap } from "@/components/sheenui/charts/heatmap";
import { type HeatmapColumn } from "@/components/sheenui/charts/heatmap/kit";
// Package build (after the first npm release, or a packed tarball): import { Heatmap, type ChartRow, type HeatmapColumn } from "@sheenui/theme";
const months: HeatmapColumn[] = [0, 1, 2, 3].map((m) => ({ key: `m${m}`, label: `Month ${m}` }));
// Later months are missing (not yet happened): drawn hatched, never as 0.
const cohorts: ChartRow[] = [
{ cohort: "Jan 2026", m0: 100, m1: 57, m2: 44, m3: 36 },
{ cohort: "Feb 2026", m0: 100, m1: 54, m2: 41 },
{ cohort: "Mar 2026", m0: 100, m1: 59 },
{ cohort: "Apr 2026", m0: 100 },
];
export function Example() {
return (
<Heatmap
data={cohorts}
index="cohort"
columns={months}
domain={[0, 100]}
steps={5}
showValues
color={7}
format={(n) => `${n}%`}
legendLabel="Retained"
aria-label="Share of each signup cohort still active, by month"
/>
);
}Heatmap
HeatmapLabels keys and English defaults (4)
HeatmapTable
ChartTip props
ChartValueTable props
MissingValue props
SequentialLegend props
Keyboard
Accessibility
- The grid is a focusable figure named by its aria-label and described by the reading hint (“Use the arrow keys to move between cells; Home and End jump along a row.”).
- Missing values are hatched, never painted as zero, and every cell's value is in the tooltip and the table view.
- On narrow screens the grid scrolls sideways inside its own focusable container while the row labels stay put.
- For a non-visual reading, give ChartCard's table prop a HeatmapTable; the Chart / Table tabs then expose each value as plain table cells.
- Reduced motion: the cells appear at their final colors and data changes jump instead of morphing.
All exports on this page
ChartDockHint— Muted hint in the band a narrow chart reserves for its docked readout, shown while nothing is being read, so the band is never just empty space.ChartTip— The glass tooltip of these charts.ChartValueTable— A plain table in the ChartTable style for charts whose data isn't one row per category.Heatmap— A category × category grid coloured on a single-hue sequential scale.HeatmapTable— Every heatmap value as a table: rows × columns, missing cells read "No data".MissingValue— A table cell without a value: a dash, read as label ("No data", "Not applicable"...).SequentialLegend— The key to a sequential colour scale: a ramp (or classed swatches) between its end values.chartNumberFormat— The default number formatters of the charts, both in one locale (default "en", like formatCompact).defaultHeatmapLabels— The built-in English strings of Heatmap; spread it into your own labels and change what you need.formatPercent— 0.412 → "41.2%" (in "en", matching formatCompact); non-finite ratios read "–".hueMix— A palette hue mixed into a base colour in OKLab.placeChartTip— Where a tooltip of size goes next to the anchor mark inside bounds (all in px, relative to the chart box).scalePosition— Position of value on a [min, max] scale, optionally snapped to steps classes (0–1).sequentialColor— One step of a single-hue sequential ramp: t = 0 sits just off the chart surface, 1 is the full palette hue.
When to use Heatmap
- Use it as a matrix heatmap for a category-by-category grid, such as traffic by weekday and time of day, error counts by service and hour, or feature usage by plan, where color encodes the value. Use it for a correlation heatmap by putting the variables on both axes and the coefficient in each cell.
- Use onCellClick to make cells drill into detail: it receives the row, the column key, its label and the value, so a click can filter a table below the grid.
- Use it when some cells have no data: missing values are hatched, never painted as zero, so a gap in a metric is not mistaken for a real low reading.
- Skip it when the axes are calendar days over a year, where Calendar heatmap lays them out as weeks, or when the rows are retention cohorts, where Cohort retention adds the average row.
- Pair it with ChartCard and HeatmapTable for a text view, a Select to switch the metric, and the legend with legendLabel so the color scale is named.
Frequently asked questions
Related pages
Guides that cover it
48 charts pages in all: browse them on Charts.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .