# Ohlc (/docs/charts/ohlc)

Ohlc answers "what was the price action per period?" — open, high, low, close, in a cell. Direction is encoded by
valence color AND body geometry, never color alone.

```tsx
import { Ohlc } from "@microcharts/react/ohlc";

const sessions = [ { open: 140.1, high: 143.4, low: 137.2, close: 142.3 }, { open: 142.6, high: 146.8, low: 141.0,
close: 144.9 }, { open: 144.5, high: 145.2, low: 140.1, close: 141.4 }, { open: 141.1, high: 144.7, low: 139.5, close:
143.8 }, { open: 143.9, high: 148.2, low: 142.8, close: 147.5 }, { open: 147.2, high: 149.9, low: 144.6, close: 145.9 },
];

<Ohlc data={sessions} title="ACME sessions" />
```

## Install

```tsx
import { Ohlc } from "@microcharts/react/ohlc";

<Ohlc data={sessions} title="ACME sessions" />
```

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** — watchlist table rows, ticker KPI cards.
- **Avoid for** — a single close series (Sparkline), or more than ~20 periods.


## Variants

```tsx
// open tick left, close tick right — the pre-candle convention
const sessions = [
  { open: 140.1, high: 143.4, low: 137.2, close: 142.3 },
  { open: 142.6, high: 146.8, low: 141.0, close: 144.9 },
  { open: 144.5, high: 145.2, low: 140.1, close: 141.4 },
  { open: 141.1, high: 144.7, low: 139.5, close: 143.8 },
  { open: 143.9, high: 148.2, low: 142.8, close: 147.5 },
  { open: 147.2, high: 149.9, low: 144.6, close: 145.9 },
];

<Ohlc data={sessions} mode="bars" />
<Ohlc data={sessions} label="last" />
```

## Edge cases

```tsx
// open === close → neutral color and a minimum 1-unit body, so a flat
// session stays visible instead of vanishing
<Ohlc
  data={[
    { open: 100, high: 103, low: 98, close: 102 },
    { open: 102, high: 104, low: 99, close: 102 },
    { open: 102, high: 105, low: 100, close: 101 },
  ]}
/>
```

```tsx
<Ohlc data={[{ open: 100, high: 104, low: 97, close: 103 }]} />
```


## Why this default

`maxPeriods` renders the most recent N sessions and warns in development past it — data is truncated visibly, never
averaged into fake candles. Bodies keep a minimum 1-unit height so doji sessions stay visible.

## Accessibility

The accessible name is the run read — **"20 periods. Last close 150.3, up 7.4%; range 136.4 to 156."** The interactive
entry announces each session's four prices (**"Period 18 of 20: open 145.6, high 150.6, low 141.6, close 144.1."**).

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) | `{ open; high; low; close }[]` | Periods, oldest first. |
| `mode` | `"candle" \| "bars"` | Candle bodies or open/close ticks. |
| `maxPeriods` | `number` | Renders the most recent N (never averaged). |
| `label` | `"last" \| "none"` | Last close 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).
