# ChangePoint (/docs/charts/change-point)

An error rate sat at 30 for two weeks, then sat at 48. ChangePoint shades the two regimes, draws a mean hairline through
each, and marks the break between them, so a reader gets "errors stepped up here" rather than "errors are high". The
detector is a **documented heuristic, not statistics**: a two-segment mean-shift found by binary segmentation, accepted
only when the split both cuts the variance enough and clears an effect-size threshold, so a constant series shows no
break. Pass your own break indices and detection switches off — the chart becomes pure annotation.

```tsx
import { ChangePoint } from "@microcharts/react/change-point";

<ChangePoint
  data={[
    30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
    48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
  ]}
  label="delta"
  title="Error rate"
/>
```

## Install

```tsx
import { ChangePoint } from "@microcharts/react/change-point";

<ChangePoint data={errors} label="delta" title="Error rate" />
```

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

## Try it

```tsx
import { ChangePoint } from "@microcharts/react/change-point/interactive";

<ChangePoint
  data={errors}
  label="delta"
/>
```

## When to use it

Use it for context around an anomaly, an error rate / latency / cost that stepped to a new level, or annotating a known
deploy or incident with explicit `breaks`. Skip it for a gradual trend (Sparkline) or a plain time series with no regime
question.

## Sizing

**annotate a known deploy (explicit break)**

```tsx
<ChangePoint data={errors} breaks={[14]} />
```

**a gradual ramp has no level shift**

```tsx
<ChangePoint data={ramp} />
```

## Variants

```tsx
<ChangePoint
  data={[
    30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
  ]}
  breaks={[14]}
/>
<ChangePoint data={[20, 21, 23, 24, 26, 27, 29, 30, 32, 33, 35, 36, 38, 39, 41, 42, 44, 45, 47, 48]} />
```

This is a mean-shift test, not a trend test. A steady ramp is still fitted as two regimes: the second variant above
reports a shift around point 10. Pass `breaks` explicitly when you already know the series is trending rather than
stepping.

## Edge cases

```tsx
<ChangePoint
  data={[3000, 3000, 3000, 3000, 3000, 3000, 3000, 5200, 5200, 5200, 5200, 5200, 5200]}
  label="delta"
  locale="de-DE"
/>
```

```tsx
// n < 8: auto-detection never fires, even on an obvious jump —
// pass explicit breaks for series this short
<ChangePoint data={[10, 10, 10, 50, 50, 50]} />
```

```tsx
<ChangePoint data={[42]} />
```

With a `locale`, the summary and delta label format their numbers in that locale's own grouping and decimal marks.
Auto-detection (`breaks="auto"`) only runs at 8 or more points. A six-point series with an obvious jump still renders as
one flat, unbroken regime unless you pass `breaks` explicitly, because a two-segment fit on that few points is mostly
noise. A single point has no line to draw and no break to find; `data={[]}` renders the frame with the "no data" summary
and no marks.

## Four homes

**In a sentence**

```tsx
<p>
  Error rate this week{" "}
  <span className="mc-inline">
    <ChangePoint data={errors} summary={false} />
  </span>{" "}
  — step-up on day 14, regime break at 2.1%.
</p>
```

**In a table cell**

```tsx
<td>
  <ChangePoint data={errors} />
</td>
```

**In a KPI card**

```tsx
<div className="kpi">
  <span className="figure">2.1%</span>
  <span className="unit">post-change regime</span>
  <ChangePoint data={errors} />
</div>
```

**In a tab header**

```tsx
<button className="tab">
  checkout <ChangePoint data={errors} />
</button>
```

## Accessibility

The accessible name states the shift, the break, the regime means, and what followed: **"Level shifted up 60% around
point 14 (mean 30 → 48); stable since."** With no detected shift it reads "No clear level shift across N points." The
interactive entry steps the points with ←/→ (value + regime) and cycles the breaks with Tab, each announcing its mean
shift.

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, press `Escape`, or
press outside the chart. On touch, a tap pins and a drag scrubs.

## Props

| Prop | Type | Description |
| --- | --- | --- |
| `data` (required) | `number[]` | A single series. |
| `breaks` | `"auto" \| number[]` | Explicit indices override the heuristic entirely — the production path. |
| `maxItems` | `number` | Max detected breaks (1–3). More regimes stop being glanceable. |
| `means` | `boolean` | Per-regime mean hairlines (default true). |
| `label` | `"delta" \| "none"` | Signed % across the most recent break, in a 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).
