# GradedBand (/docs/charts/graded-band)

GradedBand prints one number's uncertainty as nested central intervals, graded by opacity, with a median tick. Opacity
maps to probability level and nothing else. It is **never** a bar from zero: a bar with an error whisker induces
edge-literalism bias, where the bar's end reads as the answer and the whisker as noise, and a graded band has no
endpoint to over-read. Inner intervals are clipped inside their outer, so quantile rounding can never invert the
nesting.

```tsx
<GradedBand
  data={Array.from({ length: 160 }, (_, i) => 21 + Math.round(9 * Math.sin(i) + 6 * Math.sin(i * 2.3)))}
  label="median"
  title="Forecast estimate"
  width={240}
  height={16}
/>
```

## Install

```tsx
import { GradedBand } from "@microcharts/react/graded-band";

<GradedBand data={posterior} label="median" title="Forecast estimate" />
```

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 { GradedBand } from "@microcharts/react/graded-band/interactive";

<GradedBand
  data={posterior}
  label="median"
/>
```

## When to use it

Use it for a forecast with its uncertainty, estimate-vs-actual in a KPI card, and posterior summaries. For countable
odds use QuantileDots; for a forecast over time, ForecastCone.

## Sizing

**estimate vs actual**

```tsx
// the dot is a distinct shape from the median tick
<GradedBand data={posterior} value={28} />
```

**soft edge = approximate**

```tsx
<GradedBand data={posterior} softEdge />
```

## Variants

```tsx
const posterior = Array.from(
  { length: 160 },
  (_, i) => 21 + Math.round(9 * Math.sin(i) + 6 * Math.sin(i * 2.3)),
);

<GradedBand data={posterior} value={28} />
<GradedBand data={posterior} softEdge />
```

```tsx
const drift = Array.from(
  { length: 160 },
  (_, i) => (21 + Math.round(9 * Math.sin(i) + 6 * Math.sin(i * 2.3))) / 10,
);

<GradedBand data={drift} label="median" locale="de-DE" />
```

With a `locale`, the median label and the accessible summary follow that locale's decimal mark — the label above renders
"2,2", not "2.2".

## Edge cases

```tsx
// no spread → no interval to grade: only the median tick renders,
// and the summary says so instead of faking a band
<GradedBand data={[42, 42, 42, 42, 42, 42]} />
```

The accessible name for that strip is **"Point value 42, no interval."** A degenerate sample is announced as a point
estimate rather than as certainty about a range.

```tsx
// the observed dot always stays on-scale: the domain stretches to
// include it, compressing the band instead of clipping the miss
<GradedBand
  data={[19, 20, 21, 21, 22, 22, 23, 23, 24, 26]}
  value={48}
/>
```

## Four homes

**In a sentence**

```tsx
<p>
  Forecast estimate{" "}
  <span className="mc-inline">
    <GradedBand data={posterior} summary={false} />
  </span>{" "}
  — 50% band spans 17–21, point at 19.
</p>
```

**In a table cell**

```tsx
<td>
  <GradedBand data={posterior} />
</td>
```

**In a KPI card**

```tsx
<div className="kpi">
  <span className="figure">19</span>
  <span className="unit">median estimate</span>
  <GradedBand data={posterior} />
</div>
```

**In a tab header**

```tsx
<button className="tab">
  Revenue <GradedBand data={posterior} />
</button>
```

## Accessibility

The accessible name states the median with the innermost and outermost intervals. For the forecast above that is
**"Median 22; 50% within 15–27, 95% within 8–36."** The interactive entry roves the band edges, announcing each
interval's coverage and bounds.

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[]` | Sample / posterior draws; the component derives the intervals. |
| `levels` | `number[]` | 1–3 nested central intervals (default [50, 80, 95]). |
| `value` | `number` | Observed value overlaid as a dot. |
| `softEdge` | `boolean` | Fade past the outer band — 'this is approximate'. |
| `label` | `"median" \| "none"` | States the median in a right gutter (default none). |
| `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).
