# MiniBar (/docs/charts/mini-bar)

MiniBar answers "which category is biggest, and by roughly how much?". Bars are always zero-anchored, and the data's own
order is the default truth — weekday order or funnel order carries meaning that ranking would destroy, so `order` is
explicit, never silent.

```tsx
<MiniBar
  data={[
    { label: "East", value: 940 },
    { label: "West", value: 410 },
    { label: "South", value: 620 },
    { label: "North", value: 120 },
  ]}
  title="Sales by region"
  width={150}
  height={48}
/>
```

## Install

```tsx
import { MiniBar } from "@microcharts/react/mini-bar";

<MiniBar data={regions} title="Sales by region" />
```

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** — per-row category mix in tables, small comparisons in KPI cards.
- **Avoid for** — more than 8 categories (a full bar chart) or time series (SparkBar).


## Variants

```tsx
// reordering changes what the chart SAYS, so it's a data prop
<MiniBar data={regions} order="desc" />
<MiniBar data={regions} highlight="South" />
```

```tsx
// bars extend below zero; positive engages the valence tokens
<MiniBar
  data={[
    { label: "Mon", value: 4 },
    { label: "Tue", value: -2 },
    { label: "Wed", value: 6 },
    { label: "Thu", value: -1 },
    { label: "Fri", value: 3 },
  ]}
  positive="up"
/>
```

```tsx
<MiniBar
  data={[
    { label: "East", value: 12400 },
    { label: "West", value: 8600 },
  ]}
  locale="de-DE"
/>
```

The extremes named in the summary follow `format`/`locale` — 12400 reads "12.400" under `de-DE` rather than the English
"12,400".

## Edge cases

```tsx
// a missing category leaves a gap instead of shifting its neighbors
<MiniBar data={[
  { label: "a", value: 5 },
  { label: "b", value: null },
  { label: "c", value: 7 },
]} />
```

```tsx
<MiniBar data={[{ label: "Only", value: 4 }]} />
```

A `null` value draws no bar but keeps its band, so the two real bars around it stay exactly as far apart as a fully
populated row — alignment across a column of MiniBars survives missing data. A single category still renders and its
summary says so plainly ("1 category…") rather than degenerating into a bare-bar special case. Past 8 categories the
component still renders every bar (nothing is dropped or truncated) but logs a dev warning — MiniBar is a cell chart,
and a wider comparison belongs in a full bar chart.


## Why this default

Unsorted by default: the data's order often IS information. Null values keep their slot as a gap, so a missing category
never shifts its neighbors. Explicit domains are widened to include zero — a bar whose length doesn't start at zero is a
lie, so the component refuses to draw one.

## Accessibility

The accessible name carries count and extremes — **"4 categories. Highest East 940, lowest North 120."** The interactive
entry announces each bar with its rank: **"East: 940 — 1st of 4."**

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) | `{ label; value }[]` | Categories in meaningful order. |
| `order` | `"data" \| "desc" \| "asc"` | Ranking read vs positional read — data-facing, not styling. |
| `highlight` | `number \| string` | Index or label to emphasize. |
| `orientation` | `"horizontal" \| "vertical"` | Rows for wider, shorter cells. |
| `positive` | `"up" \| "down"` | Engages pos/neg tokens on signed data. |
| `label` | `"none" \| "max"` | Peak-value readout (vertical only; 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).
