Cohort Retention Chart for React
A React cohort retention chart shows how many people from each starting week or month are still around. Pass data as readonly CohortRow[]: takes one row per cohort, oldest first.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/cohort-chart.jsonWeekly retention by signup cohort
Use the arrow keys to move between cells; Home and End jump along a row, Ctrl+Home and Ctrl+End to the corners.
CohortChartCohortTablecohortModelcohortPercentdefaultCohortChartLabels- +3 more
Weekly cohorts
Twelve weekly signup cohorts. Switch between percentages and user counts: one glint sweeps the new numbers in, and the colors stay on retention so cohorts of different sizes stay comparable. Tab into the grid and use the arrow keys; Ctrl+Home / Ctrl+End jump to the corners.
Weekly retention
Signups from Jan 5 to Mar 23, 2026
Use the arrow keys to move between cells; Home and End jump along a row, Ctrl+Home and Ctrl+End to the corners.
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
import { CohortChart } from "@/components/sheenui/charts/cohort-chart";
import { type CohortRow } from "@/components/sheenui/charts/cohort-chart/parts";
import { CohortTable } from "@/components/sheenui/charts/cohort-chart/table";
import { NumberTicker } from "@/components/sheenui/number-ticker/number-ticker";
// Package build (after the first npm release, or a packed tarball): import { ChartCard, NumberTicker, CohortTable, CohortChart, type CohortRow } from "@sheenui/theme";
// This example also uses number-ticker: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/number-ticker.json
const cohorts: CohortRow[] = [
{ cohort: "Jan 5", size: 1284, values: [1284, 560, 399, 356, 300, 257 /* … */] },
{ cohort: "Jan 12", size: 1342, values: [1342, 570, 442, 356, 337 /* … */] },
// … later cohorts have fewer periods: they haven't reached them yet
];
// Weighted week-4 retention of the cohorts that have reached week 4
const reached = cohorts.filter((row) => typeof row.values[4] === "number");
const week4 =
reached.reduce((sum, row) => sum + (row.values[4] ?? 0), 0) /
reached.reduce((sum, row) => sum + row.size, 0);
export function Example() {
return (
<ChartCard
title="Weekly retention"
aside={<NumberTicker value={week4} format={{ style: "percent", maximumFractionDigits: 1 }} />}
table={<CohortTable data={cohorts} labels={{ period: (i) => `Week ${i}` }} />}
>
<CohortChart
data={cohorts}
aria-label="Weekly retention by signup cohort"
/>
</ChartCard>
);
}Monthly cohorts from ratios, sticky headers
valuesAre="ratios" takes retention shares (0–1) straight from your warehouse. maxHeight makes the table scroll inside its card: the header row and the cohort column stay put. steps={5} classes the colors; labels.period names the columns.
Monthly retention
Paid plans, Jul 2025 to Mar 2026, by cohort
Use the arrow keys to move between cells; Home and End jump along a row, Ctrl+Home and Ctrl+End to the corners.
import { CohortChart } from "@/components/sheenui/charts/cohort-chart";
// Package build (after the first npm release, or a packed tarball): import { CohortChart } from "@sheenui/theme";
<CohortChart
data={[
{ cohort: "Jul 2025", size: 8420, values: [1, 0.366, 0.29, 0.251 /* … */] },
// …
]}
valuesAre="ratios"
color={3}
steps={5}
maxHeight={300}
average={false}
labels={{ period: (i) => `M${i}` }}
aria-label="Monthly retention by signup cohort"
/>Files to copy
14 folders · 28 files · 4 packages
- From
theme/src/ components/charts/{cohort-chart.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, heatmap.tsx}components/charts/chart-parts/components/charts/cohort-chart/components/charts/heatmap/components/drawer/parts/sheet.tsxcomponents/kbd/components/menu/components/segmented/components/skeleton/components/status-icons/hooks/{use-controllable.ts, use-direction.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/cohort-chart.jsonRegistry item: cohort-chart. The styles need the Tailwind v4 glass UI setup.- The examples also use
components/number-ticker/lib/canvas-effects.ts
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/number-ticker.json- 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".
Props
CohortChartLabels keys and English defaults (14)
CohortTable props
Keyboard
Accessibility
- A real table with role=“grid”: screen readers hear the cohort and the period with every cell, plus the other measure (“41.2%, 529 of 1,284 users”).
- Cells not reached yet stay blank and read “Not yet reached”, never 0%.
- Text inside each cell is black or white, whichever contrasts more with its fill (at least 4.5:1).
- The view switch is a toggle group; the change is visible in every cell and in the grid's reading.
- Touch: rows are 44px tall, a tap pins the tooltip; on narrow screens it docks above the grid.
All exports on this page
CohortChart— Retention cohort table: one row per cohort, one column per period since it started.CohortTable— Every cohort as plain text: size, then "41.2% (529)" per period.cohortModel— Ratios and counts for every cohort, plus the weighted average of each period.cohortPercent— Retention as a percentage with one fixed decimal ("18.0%", never "18%" beside "18.5%"), so a column of them lines up.defaultCohortChartLabels— The built-in English strings of CohortChart; spread it into your own labels and change what you need.
When to use the cohort retention chart
- Use it as a retention heatmap (a cohort analysis table) where each row is a signup month and each column is periods since signup, with the cell color showing the share of the cohort still active.
- Use it to judge whether a product change helped: the weighted-average row on top gives a baseline, and each cell tooltip compares its retention with that average.
- Show user counts as well as percentages with the built-in switch, since the color always follows retention and cohorts of different sizes stay comparable.
- Skip it when you track one population over time, where a Line chart of a single retention curve is clearer, or when the rows are not cohorts, where a Heatmap is the generic grid.
- Pair it with ChartCard for the title and export, a Select to change the cohort granularity, and onCellClick to open a user list for the clicked cell in a Drawer or Dialog.
Frequently asked questions
Related pages
48 charts pages in all: browse them on Charts.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .