# Micro trend

One or more lines over time, small enough for a table cell. Forecasts read as forecasts: dashed, with a P10–P90 band and a marker where actuals stop. Hover to glide the crosshair and read every series.

Docs: https://ui.twelfth.ai/micro-trend · Category: Charts · Updated: 2026-10-30

## Install

```bash
npx shadcn@latest add https://ui.twelfth.ai/r/micro-trend.json
```

```tsx
import { MicroTrend } from "@/components/ui/micro-trend"
```

## Example

```tsx
<MicroTrend
  label="Unit sales and forecast, 12 weeks"
  points={weeks} // [{ at: "2026-08-03", values: { actual: 420, forecast: null, p10: null, p90: null } }, …]
  series={[
    { key: "actual", label: "Units sold", color: "#0d9488", weight: 1.8 },
    { key: "forecast", label: "Forecast", color: "#64748b", dashed: true },
  ]}
  bands={[{ lower: "p10", upper: "p90", label: "P10–P90" }]}
  marker={{ at: thisWeek, label: "This week" }}
  width={160}
  height={44}
  formatValue={(n) => n.toLocaleString("en-AU")}
  footer={<>
    <ChangeIndicator label="vs fcst" value={6} higherIs="better" format={(n) => `${n}%`} />
    <MicroStat label="MAPE" value="11%" hint="Forecast error, last 8 weeks" />
  </>}
/>
```

## This year vs last

```tsx
<MicroTrend
  label="Unit sales, this year against last"
  points={weeks}
  series={[
    { key: "ty", label: "This year", color: "#0d9488", weight: 1.8 },
    { key: "ly", label: "Last year", color: "#a8a29e" },
  ]}
  footer={<ChangeIndicator label="vs LY" value={6.2} higherIs="better" format={(n) => `${n}%`} />}
/>
```

## Stock vs reorder point

Actual stock, then projected at the forecast rate of sale, against the reorder point.

```tsx
<MicroTrend
  label="Stock on hand, actual then projected"
  points={weeks}
  series={[
    { key: "soh", label: "Stock on hand", weight: 1.8 },
    { key: "projected", label: "Projected", dashed: true },
  ]}
  reference={{ value: 600, label: "reorder point", tone: "exposed" }}
  marker={{ at: thisWeek, label: "This week" }}
  footer={<MicroStat label="reorder in" value="2 wks" />}
/>
```

## Sell-through vs plan

```tsx
<MicroTrend
  label="Sell-through against plan"
  points={weeks}
  series={[{ key: "actual", label: "Sell-through" }, { key: "plan", label: "Plan", dashed: true }]}
  formatValue={(n) => `${n}%`}
/>
```

## In a table

Right-aligned in a cell, the way a range review reads.

```tsx
<td className="text-right">
  <MicroTrend align="end" label={line.name} points={line.weeks} series={series} bands={bands} />
</td>
```

## Not enough data

```tsx
<MicroTrend label="New line" points={[oneWeek]} series={series} /> // renders "collecting"
```

## MicroTrend props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `points` (required) | `{ at, values: Record<string, number \| null> }[]` |  | Samples in any order; sorted by time. A null value breaks that series' line. |
| `series` (required) | `{ key, label, color?, weight?, dashed? }[]` |  | Which value keys to draw and how. |
| `label` (required) | `string` |  | What the chart shows, for screen readers. |
| `bands` | `{ lower, upper, label, color? }[]` | `[]` | Shaded ranges between two keys, e.g. P10 to P90. |
| `marker` | `{ at, label }` |  | A vertical line, e.g. where actuals stop. |
| `reference` | `{ value, label?, tone? }` |  | A dashed horizontal line: a target, a reorder point. |
| `domain` | `[number, number]` |  | The value axis. Defaults to the data's range. |
| `zeroBased` | `boolean` | `false` | Start the default axis at zero. |
| `range` | `[Date \| number, Date \| number]` |  | The time axis. Defaults to first to last sample. |
| `gapAfter` | `number (ms)` |  | Break a line where two samples are further apart than this. |
| `formatValue` | `(value, series) => string` |  | Values in the tooltip. |
| `formatAt` | `(date) => string` |  | The tooltip's heading. |
| `readout` | `(point) => ReactNode` |  | Extra tooltip lines for the hovered sample. |
| `footer` | `ReactNode` |  | Under the chart, e.g. a ChangeIndicator and a MicroStat. |
| `onExpand` | `() => void` |  | Makes the chart a button that opens a larger view. |
| `width / height` | `number` | `120 / 34` | Pixels. |
| `align` | `"start" \| "end"` | `"end"` | Footer alignment; end for a numeric column. |

## Notes

- Lines draw in on mount; reduced motion skips it. The crosshair and dots glide between samples.
- Arrow keys, Home and End step through samples when the chart has focus.
- Uses your tooltip component; the stock shadcn one inverts colours, which the readout is written to suit.

---

twelfth UI: Open-source (MIT) shadcn components for category managers and retail buying teams, by twelfth (https://twelfth.ai). React and TypeScript on shadcn's Base UI styles and Tailwind CSS v4. Components take plain props and fetch no data. Every block: https://ui.twelfth.ai/llms.txt
