# SparkBar (/docs/charts/sparkbar)

SparkBar renders discrete values as compact bars from a zero baseline. In `winloss` mode it collapses each value to its
sign — a streak you can read at a glance: wins above the mid-line, losses below, and a tie (`0`) as a thin neutral dash
on it.

```tsx
<SparkBar data={[4, 6, 2, 8, 5, 9]} width={120} height={32} title="Deploys per day" />
```

## Install

```tsx
import { SparkBar } from "@microcharts/react/sparkbar";

<SparkBar data={[4, 6, 2, 8, 5, 9]} title="Deploys per day" />
```

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** — discrete magnitudes, win–loss streaks, period-over-period counts.
- **Avoid for** — a continuous trend shape (use [Sparkline](/docs/charts/sparkline)) or hundreds of points, where bars
  become noise.

## Sizing

`width` and `height` are viewBox units that also set the rendered pixel box. Omit them and drive the width from CSS for
a chart that fills its container — the viewBox keeps the aspect ratio.

## Variants

```tsx
<SparkBar data={[4, 6, 2, 8, 5, 9]} />
```

```tsx
<SparkBar data={[1, -1, 1, 1, -1, 1, -1]} mode="winloss" />
```

```tsx
// a 0 is a tie — a neutral dash on the mid-line, never a win or a loss
<SparkBar data={[1, -1, 0, 1, 0, -1, 1]} mode="winloss" />
```

```tsx
<SparkBar data={[4, 6, 2, 8, 5, 9]} label="last" />
```

```tsx
<SparkBar data={[4200, 6100, 2800, 8600]} label="last" locale="de-DE" />
```

The endpoint label and accessible summary both follow `format`/`locale` — 8600 reads "8.600" under `de-DE` rather than
the English "8,600".

## Edge cases

```tsx
<SparkBar data={[]} title="No deploys yet" />
```

```tsx
<SparkBar data={[6]} title="One deploy" />
```

An empty series renders no bars and an accessible name that says so, rather than a flat or invented baseline. A single
value still renders as one zero-anchored bar — `winloss` mode treats it the same way a longer streak would: a lone win,
loss, or tie.


## Why this default

Bars, not a line, because SparkBar's job is discrete magnitudes — deploy counts, daily totals — where each period is its
own thing, not a sampled point on a continuous curve. Zero-anchored always: a bar whose length doesn't start at zero
misstates its magnitude. `winloss` mode goes further and discards magnitude entirely on purpose, collapsing each value
to a three-state streak (win above the mid-line, loss below, tie a thin dash on it) because for a streak, sign is the
whole story and a magnitude axis would just be noise. Sign is doubled by position AND color everywhere signed data
appears, so direction survives forced-colors and never depends on color alone. In `bar` mode the endpoint bar takes the
accent — "where did it land" is usually the first question a run of counts answers; in `winloss` mode it keeps its
win/loss/tie color instead, because there the sign is what matters at every position, endpoint included.

## Accessibility

Announced from the data — the example above reads:

> Deploys per day. Trending up 125%. Range 2 to 9. Last value 9.

Sign is doubled by position (above or below the baseline), never by color alone, so the chart survives forced-colors and
color-blind viewing.

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) | `number[]` | Values; negatives dip below the baseline. |
| `mode` | `"bar" \| "winloss"` | Magnitude bars, or a win/loss/tie streak (sign only). |
| `gap` | `number` | Empty fraction of each slot (0–0.9). |
| `label` | `"none" \| "last"` | Direct endpoint value label. |
| `positive` | `"up" \| "down"` | "up" (default); "down" flips which sign is good. |
| `title` | `string` | Accessible name; joins the auto summary. |
| `summary` | `string \| false` | Override or disable the auto summary. |
| `locale` | `string \| string[]` | BCP 47 locale(s) for the endpoint label and summary. |
| `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).
