# EnsembleGhosts (/docs/charts/ensemble-ghosts)

EnsembleGhosts draws a faint bundle of member paths with one emphasized representative, so you can see where the
simulated futures disagree in **shape** and not only at the endpoint. Two ensembles can share an average and a final
range while running completely different routes to get there, which is what a mean line hides. The emphasized path
defaults to the real member closest to the pointwise median, so the representative is a path the simulation produced;
`emphasis="median"` draws the synthetic pointwise median instead. Ghost selection is evenly spaced endpoint-rank
quantiles, so the same input renders identically every time.

```tsx
import { EnsembleGhosts } from "@microcharts/react/ensemble-ghosts";

<EnsembleGhosts
  data={[
    [40, 41, 43, 45, 47, 50],
    [40, 39, 38, 36, 35, 33],
    [40, 42, 44, 47, 49, 52],
    [40, 40, 41, 41, 42, 43],
    [40, 43, 47, 52, 56, 61],
    [40, 38, 35, 32, 30, 28],
    [40, 41, 42, 44, 45, 46],
    [40, 39, 40, 41, 42, 44],
  ]}
  endpoints
  title="Simulated futures"
/>
```

## Install

```tsx
import { EnsembleGhosts } from "@microcharts/react/ensemble-ghosts";

<EnsembleGhosts data={futures} title="Simulated futures" />
```

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 { EnsembleGhosts } from "@microcharts/react/ensemble-ghosts/interactive";

<EnsembleGhosts
  data={futures}
/>
```

## When to use it

Use it for a KPI card that shows the futures rather than the average, for Monte-Carlo and simulation output where paths
disagree in shape, and for showing that outcomes fan out. When you need interval precision, use ForecastCone; for a
single path, use Sparkline.

## Sizing

**endpoint dots (countable spread)**

```tsx
<EnsembleGhosts data={futures} endpoints />
```

**synthetic median path**

```tsx
<EnsembleGhosts data={futures} emphasis="median" />
```

## Variants

```tsx
<EnsembleGhosts
  data={[
    [40, 41, 43, 45, 47, 50],
    [40, 39, 38, 36, 35, 33],
    [40, 42, 44, 47, 49, 52],
    [40, 43, 47, 52, 56, 61],
    [40, 38, 35, 32, 30, 28],
  ]}
  endpoints
/>
<EnsembleGhosts
  data={[
    [40, 41, 43, 45, 47, 50],
    [40, 39, 38, 36, 35, 33],
    [40, 42, 44, 47, 49, 52],
    [40, 43, 47, 52, 56, 61],
    [40, 38, 35, 32, 30, 28],
  ]}
  emphasis="median"
/>
```

`endpoints` marks where each ghost lands. `label="end"` is the default and states the emphasized path's landing value in
a right gutter; `label="none"` drops it.

## Edge cases

```tsx
<EnsembleGhosts data={[[40, 43, 47, 52, 56, 61]]} />
```

```tsx
<EnsembleGhosts
  data={[
    [4000, 4100, 4300, 4500, 4700, 5000],
    [4000, 3900, 3800, 3600, 3500, 3300],
    [4000, 4200, 4400, 4700, 4900, 5200],
  ]}
  locale="de-DE"
/>
```

With one member there is no bundle to draw, so the chart renders that single path as the representative and the summary
states its ending value rather than a spread. A member containing a non-finite value (`NaN`, `Infinity`) is excluded
from ghost selection and from the median entirely, rather than gapped mid-path, and a dev-only console warning flags it:
a partially invalid future usually means bad simulation output.

## Four homes

**In a sentence**

```tsx
<p>
  Simulated futures{" "}
  <span className="mc-inline">
    <EnsembleGhosts data={futures} summary={false} />
  </span>{" "}
  — 70% of paths finish above target.
</p>
```

**In a table cell**

```tsx
<td>
  <EnsembleGhosts data={futures} />
</td>
```

**In a KPI card**

```tsx
<div className="kpi">
  <span className="figure">70%</span>
  <span className="unit">paths above target</span>
  <EnsembleGhosts data={futures} />
</div>
```

**In a tab header**

```tsx
<button className="tab">
  Base <EnsembleGhosts data={futures} />
</button>
```

## Accessibility

The accessible name states the endpoint spread and the typical path: **"5 simulated paths end between 28 and 61; typical
path ends near 50."** The static frame is not a hypothetical-outcome plot. The HOP loop, which flips through the members
one at a time on hover, lives only in the interactive entry; with reduced motion, ←/→ step the members discretely
instead, and each one is announced with its endpoint.

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[][]` | Ensemble members — 2–50 simulated paths. |
| `ghosts` | `number` | Rendered member count (deterministic endpoint-rank selection). Default 8, cap 12. |
| `emphasis` | `"nearest-median" \| "median" \| number` | A real median-like member, the synthetic median, or a pinned member. |
| `endpoints` | `boolean` | Ghost endpoint dots — makes the final-value spread countable. |
| `label` | `"end" \| "none"` | Emphasised path endpoint in a right gutter (default end). |
| `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).
