# PairedBars (/docs/charts/paired-bars)

East came in at 940 against a plan of 1,200, West a little over its own: PairedBars draws each value beside its
reference, category by category. Both bars in a pair share one zero-anchored domain, so their lengths are always
comparable. The reference is muted by two structural cues, opacity _and_ width, never color alone.

```tsx
import { PairedBars } from "@microcharts/react/paired-bars";

<PairedBars data={[
  { label: "East", value: 940, ref: 1200 },
  { label: "West", value: 410, ref: 400 },
]} title="Actual vs plan" />
```

## Install

```tsx
import { PairedBars } from "@microcharts/react/paired-bars";

<PairedBars data={regions} title="Actual vs plan" />
```

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 { PairedBars } from "@microcharts/react/paired-bars/interactive";

<PairedBars
  data={regions}
/>
```

## When to use it

Use it for budget vs actual per region and target vs result rows. For data without a reference series use MiniBar, and
keep it to 5 pairs or fewer.

## Sizing

**table cell**

```tsx
<PairedBars data={row.mix} width={60} height={20} />
```

**overlay for tight cells**

```tsx
// ghost = the reference, never the value
<PairedBars data={row.mix} mode="overlay" />
```

## Variants

```tsx
// the ghost is always the REFERENCE, never the value
<PairedBars
  data={[
    { label: "East", value: 940, ref: 1200 },
    { label: "West", value: 410, ref: 400 },
  ]}
  mode="overlay"
/>
```

Grouped is the default because overlapping bars hide small overshoots. Reach for `mode="overlay"` when the cell is too
tight for two bars per pair.

```tsx
<PairedBars
  data={[
    { label: "East", value: 940, ref: 1200 },
    { label: "West", value: 410, ref: 400 },
  ]}
  positive="up"
/>
```

```tsx
<PairedBars
  data={[{ label: "East", value: 9400, ref: 12000 }]}
  locale="de-DE"
/>
```

The gap named in the summary follows `format`/`locale` — 12000 reads "12.000" under `de-DE` rather than the English
"12,000".

## Edge cases

```tsx
// value bar alone; the interactive entry announces "no reference"
<PairedBars data={[{ label: "East", value: 940, ref: null }]} />
```

```tsx
<PairedBars data={[{ label: "East", value: 940, ref: 1200 }]} />
```

A pair whose `ref` is `null` draws its value bar alone, with no ghost and no zero-width placeholder, and the interactive
entry announces it as **"East: 940, no reference."** A chart where _every_ reference is missing dev-warns and points you
to MiniBar. Past 5 pairs the grouped read blurs, so the component still renders every pair and logs a dev warning.

## Four homes

**In a sentence**

```tsx
<p>
  Regional spend vs plan this quarter{" "}
  <span className="mc-inline">
    <PairedBars data={regions} width={100} height={18} summary={false} />
  </span>{" "}
  — East is furthest off target, 940 spent against a 1,200 budget.
</p>
```

**In a table cell**

```tsx
<td>
  <PairedBars data={[{ label: "East", value: 940, ref: 1200 }]} positive="down" />
</td>
```

**In a KPI card**

```tsx
<div className="kpi">
  <span className="figure">2 / 4</span>
  <span className="unit">regions under budget, this quarter</span>
  <PairedBars data={regions} positive="down" width={110} height={30} />
</div>
```

**In a tab header**

```tsx
<button className="tab">
  Regional <PairedBars data={[{ label: "East", value: 940, ref: 1200 }]} positive="down" width={64} height={16} summary={false} />
</button>
```

## Accessibility

The accessible name leads with the largest gap — **"2 pairs. Largest gap East: 940 vs 1,200."** The interactive entry
roves pairs and announces each as value vs reference (**"East: 940 vs 1,200."**).

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) | `{ label; value; ref }[]` | Value + reference per category. |
| `mode` | `"grouped" \| "overlay"` | Overlay puts the ref as a full-width ghost behind — halves the footprint. |
| `positive` | `"up" \| "down"` | Over/under-reference valence tint. |
| `orientation` | `"horizontal" \| "vertical"` | Rows for wide cells. |
| `locale` | `string \| string[]` | BCP 47 locale(s) for the gap named in the summary, e.g. "de-DE". |
| `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).
