# MicroScatter (/docs/charts/micro-scatter)

MicroScatter plots one dot per x/y pair to show whether two metrics move together. Dots render at 75% opacity, so
overplot reads as density instead of hiding points behind each other. Duplicates are never jittered, because position is
the encoding. Axes go unlabeled at this scale, so `title` has to name both variables, the way the demo below does. The
summary's relationship words come from a documented heuristic on |r| (≥ 0.7 strong, ≥ 0.4 moderate, ≥ 0.2 weak), and
wherever a relationship word appears, r appears beside it.

```tsx
<span className="text-lg">
  {"Latency and error rate "}
  <MicroScatter
    data={Array.from({ length: 24 }, (_, i) => ({ x: i, y: i * 3 + ((i * 7) % 5) * 6 }))}
    title="Latency vs error rate"
    style={{ width: "3em", height: "1.8em" }}
  />
  {" correlate strongly."}
</span>
```

## Install

```tsx
import { MicroScatter } from "@microcharts/react/micro-scatter";

<MicroScatter data={pairs} title="Latency vs error rate" />
```

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 { MicroScatter } from "@microcharts/react/micro-scatter/interactive";

<MicroScatter
  data={pairs}
/>
```

## When to use it

Use it for correlation in a sentence and two-metric relationships in KPI cards. Past 60 points, bin the data instead;
for ordered time series use Sparkline.

## Sizing

**in a sentence**

```tsx
latency and errors <MicroScatter data={pairs}
  style={{ width: "2.5em", height: "1.5em" }} /> correlate strongly
```

**with the trend**

```tsx
<MicroScatter data={pairs} trend />
```

## Variants

```tsx
// least-squares, linear only — never smoothed
<MicroScatter data={pairs} trend />
```

```tsx
<MicroScatter data={pairs} focal={12} />
```

## Edge cases

```tsx
<MicroScatter data={[]} title="No pairs" />
```

```tsx
<MicroScatter data={[{ x: 1, y: 2 }, { x: 2, y: 3 }]} title="Two points" />
```

```tsx
<MicroScatter data={[{ x: 5, y: 5 }, { x: 5, y: 5 }, { x: 1, y: 8 }]} />
```

Empty data draws just the frame, with "No data." as the summary. Under 3 points, or with a zero-variance cloud, the
summary states the count and stops: no correlation claim without enough evidence behind it. Coincident points are never
jittered apart. They overlap exactly, and at 75% dot opacity the overlap reads as extra density rather than hiding a
point.

## Four homes

**In a sentence**

```tsx
<p>
  Bundle size and paint time{" "}
  <span className="mc-inline">
    <MicroScatter data={pairs} height={20} summary={false} />
  </span>{" "}
  — heavier bundles paint slower, r 0.93.
</p>
```

**In a table cell**

```tsx
// concurrent requests vs p95 latency, per service
{services.map((s) => (
  <tr key={s.name}>
    <td>{s.name}</td>
    <td><MicroScatter data={s.pairs} /></td>
  </tr>
))}
```

**In a KPI card**

```tsx
<div className="kpi">
  <span className="figure">0.93</span>
  <span className="unit">r, strong positive</span>
  <MicroScatter data={pairs} trend width={200} height={90} />
</div>
```

**In a tab header**

```tsx
<button className="tab">
  Paid <MicroScatter data={pairs} width={64} height={20} /> r 0.93
</button>
```

## Accessibility

The accessible name is the count plus the evidence-backed relationship: **"24 points. Strong positive relationship (r
0.93)."** With fewer than 3 points, or a zero-variance cloud, it makes no claim at all and reads just **"2 points."**
The interactive entry steps points ordered by x and announces each formatted pair.

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) | `{ x; y }[]` | Unordered pairs. |
| `trend` | `boolean` | Least-squares line — linear only, never smoothed. |
| `focal` | `number` | Accent one point — "this one, among all of them". |
| `xDomain` | `[number, number]` | X scale (domain keeps its grammar meaning: y). |
| `domain` | `[number, number]` | Y scale — the shared grammar name, paired with xDomain. |
| `r` | `number` | Dot radius, clamped [1, 3]. |
| `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).
