# RetentionCurve (/docs/charts/retention-curve)

RetentionCurve answers "do they stay — and does the curve plateau?". It draws a **step** line (cohort periods are
discrete) on a scale **locked to 0–100%** — the full range is the honest frame for a share, so the floor is never
truncated to manufacture drama. When the curve flattens, a dotted plateau marker appears; a peer curve can ride behind
as a subordinate ghost.

```tsx
import { RetentionCurve } from "@microcharts/react/retention-curve";

<RetentionCurve
  data={[1, 0.72, 0.55, 0.47, 0.42, 0.4, 0.39, 0.385, 0.382, 0.38, 0.379, 0.378]}
  unit="week"
  title="W12 cohort"
/>
```

## Install

```tsx
import { RetentionCurve } from "@microcharts/react/retention-curve";

<RetentionCurve data={cohort} unit="week" title="W12 cohort" />
```

Setup (package + stylesheet): [Quickstart](/docs/quickstart#set-up-with-an-ai-agent) or paste [`/agent-setup.md`](/agent-setup.md) into your agent.


## When to use it

- **Good for** — a cohort retention curve in a KPI card, your decay vs an industry benchmark, spotting whether retention
  plateaus (or keeps leaking).
- **Avoid for** — a continuous signal (Sparkline) or one-number retention (Progress / Delta).


## Variants

```tsx
<RetentionCurve
  data={[1, 0.72, 0.55, 0.47, 0.42, 0.4, 0.39, 0.385, 0.382, 0.38]}
  benchmark={[1, 0.6, 0.44, 0.37, 0.33, 0.3, 0.29, 0.285, 0.282, 0.28]}
/>
<RetentionCurve
  data={[1, 0.72, 0.55, 0.47, 0.42, 0.4, 0.39, 0.385, 0.382, 0.38]}
  curve="smooth"
/>
```

## Edge cases

```tsx
<RetentionCurve data={[1]} unit="week" />
```

```tsx
// values over 1.001 are auto-detected as percent, not fraction — same curve
<RetentionCurve data={[100, 72, 55, 47, 42, 40, 39]} unit="week" />
```

```tsx
<RetentionCurve
  data={[1, 0.72, 0.55, 0.47, 0.42, 0.4, 0.39]}
  unit="week"
  label="last"
  locale="de-DE"
/>
```

A single period is too short for plateau detection (the window needs at least four finite points) and renders as a
single step with no visible line. `data` accepts either a 0–1 fraction or a 0–100 percent series — whichever the max
value implies — so a raw percent export renders identically to its fraction form without a manual divide. With a
`locale`, the percent label and every announced number follow that locale's own formatting.


## Why this default

Step line plus the full 0–100% range, because retention is a discrete share, not a continuous signal — a smoothed curve
implies between-period values that never existed, and a truncated floor exaggerates or hides the drop. The plateau
marker appears **only** when the mean period-over-period change over the tail falls below half a point — never as
decoration — and the benchmark stays a subordinate dashed ghost, never a second competing line.

## Accessibility

The accessible name states the final retention and, when detected, the plateau — **"38% retained after 10 weeks; curve
plateaus from week 6."**. The interactive entry steps the periods and announces each period's retention alongside the
benchmark's.

The interactive entry follows the shared [interaction contract](/docs/accessibility#one-interaction-contract):
arrow keys rove between units on both axes, `Home` and `End` jump to the ends, and a click, tap, `Enter` or
`Space` selects a unit — pinning its readout so it survives blur, until you select it again or press `Escape`.
On touch, a tap pins and a drag scrubs.

## Props

| Prop | Type | Description |
| --- | --- | --- |
| `data` (required) | `number[]` | Fraction retained per period (0–1 or 0–100); period 0 is typically 1.0. |
| `benchmark` | `number[]` | Peer/industry curve, drawn as a subordinate dashed ghost. |
| `plateau` | `boolean` | Detect + mark a plateau (default true). |
| `curve` | `"step" \| "smooth"` | Step (default — cohorts are discrete) or smooth (editorial). |
| `unit` | `string` | Period noun for the summary (default 'period'). |
| `label` | `"last" \| "none"` | Final retention in a right gutter. |
| `animate` | `boolean` | (interactive) Opt-in entrance motion when the chart mounts client-side — add `import "@microcharts/react/motion"` once. Inert on the server, on hydrated server HTML, and under `prefers-reduced-motion`. |

Plus the shared grammar — `data`, `domain`, `color`, `title`, `summary`, `format` — and the layout props (`width`, `height`, `className`, `style`) that every chart accepts. Interactive entries also share `animate` and `live`, and — wherever a chart has more than one navigable unit — `onActive`, `onSelect`, `selectedIndex` and `defaultSelectedIndex`; and — wherever the chart shows a hover value — `readout`. See [the shared grammar](/docs/quickstart#the-shared-grammar).
