shadcn Cohort Chart: Retention Heatmap or Curves, and How to Install One
The shadcn/ui charts have no cohort chart, and search results for one are mostly R and Tableau tutorials. Yet a cohort retention chart is on every SaaS board deck: of the customers who signed up in January, how many are still here in month 3, 6, 12? This guide covers the two ways to draw it, the mistakes that make cohort charts lie, and how to install one in a shadcn project.
Heatmap or curves?
Both charts take the same data: one row per signup cohort, with the share still active in each period since signup.
- A cohort heatmap (the "triangle") shows every exact value. Rows are cohorts, columns are months since signup, and colour shows retention. Use it when people will read individual cells: "March was weak in month 2".
- Retention curves draw one line per cohort. Use them to answer the question boards actually ask: are newer cohorts retaining better than older ones? Where does the curve flatten?
Many dashboards show both: curves for the story, the heatmap for the detail.
The checklist
- Not-yet-observed is blank, not zero. A cohort that signed up last month has no month-6 value. Drawing it as 0% makes your newest customers look like they all churned. Blank cells, and a note saying how many cohorts are still maturing.
- The average is weighted by cohort size. A 40-customer cohort shouldn't count as much as a 900-customer one. A plain average of percentages gives the wrong typical curve.
- The average only uses cohorts that reached that period. Otherwise the late months average just one or two old cohorts and look like a cliff (or a miracle).
- Above 100% is allowed, and flagged. Revenue retention can exceed 100% through expansion. The chart should allow it and say so, not clip it.
- One colour scale, light to dark. Retention is a magnitude. A red-to-green scale suggests a "bad" and "good" cut-off that doesn't exist.
- Highlight the cohorts your title is about. On curves, colour the two or three that matter and grey the rest.
Install one with the shadcn CLI
ChartslibraryUI has both: the cohort heatmap and the retention curve. They are part of Pro. After buying, install them with your access key:
pnpm dlx shadcn@latest add @chartslibraryui/cohort-heatmap @chartslibraryui/retention-curvenpx shadcn@latest add @chartslibraryui/cohort-heatmap @chartslibraryui/retention-curveyarn dlx shadcn@latest add @chartslibraryui/cohort-heatmap @chartslibraryui/retention-curvebunx --bun shadcn@latest add @chartslibraryui/cohort-heatmap @chartslibraryui/retention-curveBoth take the same data. values are shares of the starting cohort, with null for periods not reached yet:
const cohorts = [
{ cohort: "Jan 26", size: 320, values: [1, 0.78, 0.72, 0.69, 0.66] },
{ cohort: "Feb 26", size: 410, values: [1, 0.81, 0.75, 0.71, null] },
{ cohort: "Mar 26", size: 385, values: [1, 0.84, 0.77, null, null] },
];<CohortHeatmap title="March signups retain best so far" data={cohorts} />
<RetentionCurve title="Newer cohorts keep more customers after month 1" data={cohorts} />What they handle for you:
- Blank cells for periods not reached, with a note ("2 cohorts are still maturing").
- A size-weighted average from observed cells only: a row on the heatmap, and a curve on the retention curve (drawn only where at least two cohorts have data). Cohorts without a size are weighted equally, and the chart says so.
- Values above 100% are kept and noted as expansion or reactivation.
- The retention curve colours the newest cohorts with enough history and greys the rest; pass
highlightto pick others. If you pass counts instead of shares, it divides each cohort by its first value and says so.
Keep cohort charts honest
- Say what "active" means in the subtitle: logged in, paying, or still subscribed.
- Say the period: "by months since signup" (the default column labels are M0, M1, M2; change them with
periodPrefix). - Treat the newest cohorts with care. Their last points are based on one or two periods; don't headline them.
- Logo retention and revenue retention are different charts. Don't mix them in one.
Related
- The best charts for SaaS metrics dashboards (2027)
- SaaS metrics board: MRR, churn and retention in one Pro block
- Line chart: for one retention number over time