# Ohlc (/docs/charts/ohlc)

Four numbers per period, in one table cell: open, high, low, close. Together they say how far a session ran and which
way it closed, one row per instrument. Direction comes from valence color and from the body geometry, so it never rests
on color alone. `maxPeriods` renders the most recent N sessions and warns in development past that — extra periods are
dropped visibly, never averaged into composite candles.

```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.

## Try it

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

<Ohlc
  data={sessions}
/>
```

## When to use it

Use it for watchlist table rows and ticker KPI cards. For a single close series use Sparkline, and keep the count under
about 20 periods.

## Sizing

**watchlist rows**

```tsx
{tickers.map((t) => (
  <Ohlc key={t.symbol} data={t.sessions} title={t.symbol} />
))}
```

**bars with last close**

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

## 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 }]} />
```

A session that opens and closes at the same price renders neutral and keeps a minimum 1-unit body height, so a flat
period stays visible instead of collapsing to a hairline. A single period renders its own bar against its own range.

## Four homes

**In a sentence**

```tsx
<p>
  ACME closed the session at{" "}
  <span className="mc-inline">
    <Ohlc data={sessions} width={90} height={14} summary={false} />
  </span>{" "}
  $150.30, up 7.4% over 20 sessions.
</p>
```

**In a table cell**

```tsx
<td>
  <Ohlc data={ticker.sessions} title={ticker.symbol} />
</td>
```

**In a KPI card**

```tsx
<div className="kpi">
  <span className="figure">$150.30</span>
  <span className="unit">up 7.4% over 20 sessions</span>
  <Ohlc data={sessions} />
</div>
```

**In a tab header**

```tsx
<button className="tab">
  ACME <Ohlc data={ticker.sessions} />
</button>
```

## 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, press `Escape`, or
press outside the chart. 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).
