# RateVolume (/docs/charts/rate-volume)

RateVolume draws a precise rate line over low-precision **ghost volume bars**, which are the denominator. No prop
removes the bars: a 4.1% conversion rate reads very differently on 38 events than on 3,800. The bars are muted and
unlabeled because the question they answer is "enough?", not "how many?". Set `minVolume` and any period below it
renders its rate point hollow, a shape cue that survives forced-colors and print.

```tsx
<RateVolume
  data={[
    { rate: 0.023, volume: 220 },
    { rate: 0.025, volume: 190 },
    { rate: 0.028, volume: 160 },
    { rate: 0.029, volume: 130 },
    { rate: 0.031, volume: 110 },
    { rate: 0.034, volume: 90 },
    { rate: 0.036, volume: 66 },
    { rate: 0.041, volume: 38 },
  ]}
  format={{ style: "percent", maximumFractionDigits: 1 }}
  minVolume={50}
  label="last"
  title="Conversion rate"
  width={260}
  height={28}
/>
```

## Install

```tsx
import { RateVolume } from "@microcharts/react/rate-volume";

<RateVolume data={periods} minVolume={50} title="Conversion 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 { RateVolume } from "@microcharts/react/rate-volume/interactive";

<RateVolume
  data={periods}
  minVolume={50}
/>
```

## When to use it

Use it for a conversion or error rate with its denominator, a KPI card where the rate is the headline, and spotting a
big rate move on thin volume. When volume itself needs a precise read, pair a SparkBar; for a plain series use
Sparkline.

## Sizing

**flag thin denominators**

```tsx
// a 4.1% rate on 38 events renders hollow — read it with caution
const periods = [
  { rate: 0.023, volume: 220 }, { rate: 0.025, volume: 190 }, { rate: 0.028, volume: 160 },
  { rate: 0.029, volume: 130 }, { rate: 0.031, volume: 110 }, { rate: 0.034, volume: 90 },
  { rate: 0.036, volume: 66 }, { rate: 0.041, volume: 38 },
];

<RateVolume data={periods} minVolume={50} />
```

**per-period step rates**

```tsx
const periods = [
  { rate: 0.023, volume: 220 }, { rate: 0.025, volume: 190 }, { rate: 0.028, volume: 160 },
  { rate: 0.029, volume: 130 }, { rate: 0.031, volume: 110 }, { rate: 0.034, volume: 90 },
  { rate: 0.036, volume: 66 }, { rate: 0.041, volume: 38 },
];

<RateVolume data={periods} curve="step" />
```

## Variants

```tsx
const periods = [
  { rate: 0.023, volume: 220 },
  { rate: 0.028, volume: 160 },
  { rate: 0.031, volume: 110 },
  { rate: 0.036, volume: 66 },
  { rate: 0.041, volume: 38 },
];

<RateVolume data={periods} minVolume={50} />
<RateVolume data={periods} curve="step" />
```

```tsx
<RateVolume
  data={[
    { rate: 0.023, volume: 220 },
    { rate: 0.041, volume: 38 },
  ]}
  format={{ style: "percent", maximumFractionDigits: 1 }}
  volumeFormat={{ maximumFractionDigits: 0 }}
  locale="de-DE"
/>
```

`format` and `volumeFormat` both take `Intl.NumberFormatOptions` and share the same `locale`. Under `de-DE` the rate
label reads "4,1 %" and volumes group with a period ("3.800"), following that locale's own conventions rather than a
hardcoded English format.

## Edge cases

```tsx
// no denominator, no rate — the line gaps rather than interpolating
// across a period nothing was measured on
<RateVolume data={[
  { rate: 0.02, volume: 200 },
  { rate: NaN, volume: 0 },
  { rate: 0.03, volume: 180 },
]} />
```

```tsx
<RateVolume data={[]} title="No periods yet" />
```

A period with zero (or non-finite) volume renders no bar and no rate mark. A rate on **zero** volume is undefined
regardless of the input, so the line gaps across that period instead of interpolating through one nothing was measured
on, and the interactive entry announces it as **"no events"** rather than a rate. With no data at all, the chart renders
an empty root and the accessible name says **"No data."**

## Four homes

**In a sentence**

```tsx
<p>
  Conversion rate{" "}
  <span className="mc-inline">
    <RateVolume data={periods} minVolume={50} summary={false} />
  </span>{" "}
  — 4.2% on 1,240 sessions this week.
</p>
```

**In a table cell**

```tsx
<td>
  <RateVolume data={periods} minVolume={50} />
</td>
```

**In a KPI card**

```tsx
<div className="kpi">
  <span className="figure">4.2%</span>
  <span className="unit">1,240 sessions</span>
  <RateVolume data={periods} minVolume={50} />
</div>
```

**In a tab header**

```tsx
<button className="tab">
  Web <RateVolume data={periods} minVolume={50} />
</button>
```

## Accessibility

The accessible name always pairs the rate with its volume: **"4.1% on 38 events (low volume); up from 2.3% across 5
periods."** The interactive entry steps the periods, and its live region states the volume with every rate, announcing
"no events" for a zero-volume period.

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) | `{ rate; volume }[]` | Periods, oldest first — each a rate and the volume it was measured on. |
| `minVolume` | `number` | Below it, the rate mark renders hollow — 'insufficient denominator'. |
| `curve` | `"linear" \| "step"` | Step suits per-period aggregate rates. |
| `volumeFormat` | `Intl.NumberFormatOptions \| (n) => string` | Volume has different units than rate; formatted separately. |
| `unit` | `string` | Noun for the volume unit in the summary (default 'events'). |
| `volumeDomain` | `[number, number]` | Volume (bar) domain — defaults to [0, max], zero-anchored. |
| `label` | `"last" \| "none"` | Endpoint rate in a right gutter. |
| `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).
