# TrendArrow (/docs/charts/trend-arrow)

A latency number moved 8% and the table cell has room for one glyph. TrendArrow encodes the direction in the shape: up,
down, or a flat bar. Color reinforces the shape, so the read survives grayscale, print, and forced-colors. The glyph
never scales with magnitude: an arrow twice as long would claim precision this size can't carry. When the magnitude
matters, reach for [Delta](/docs/charts/delta) instead.

```tsx
import { TrendArrow } from "@microcharts/react/trend-arrow";

<TrendArrow
  value={-0.08}
  positive="down"
  format={{ style: "percent", maximumFractionDigits: 0 }}
  title="Latency vs last week"
/>
```

## Install

```tsx
import { TrendArrow } from "@microcharts/react/trend-arrow";

<TrendArrow value={-0.08} positive="down" title="Latency vs last week" />
```

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 { TrendArrow } from "@microcharts/react/trend-arrow/interactive";

<TrendArrow
  value={0.12}
  format={{ style: "percent", maximumFractionDigits: 0 }}
/>
```

## When to use it

Use it for table direction columns, dense dashboards, and inline movement cues. For exact magnitudes use Delta; for the
shape of a series use Sparkline.

## Sizing

The glyph is a fixed 16-unit box that scales like an image — size it with CSS. With `showValue` the viewBox widens to
reserve a gutter for the number, so text never paints outside the chart.

**matches the text**

```tsx
// size the glyph in em so it rides the surrounding type
<span>
  Errors <TrendArrow value={0.4} positive="down" style={{ width: "1em", height: "1em" }} />
</span>
```

**with the number**

```tsx
// showValue widens the viewBox for the formatted value
<TrendArrow value={0.12} showValue format={{ style: "percent" }}
  style={{ height: 22 }} />
```

## Variants

Three glyph weights for three densities, a declared noise floor, and the number itself when the glyph alone is too
terse. The default arrow keeps its shaft and head legible at 8 px and in forced-colors, where lighter marks blur.

```tsx
<TrendArrow value={1} glyph="arrow" />
<TrendArrow value={1} glyph="triangle" />
<TrendArrow value={1} glyph="chevron" />
```

```tsx
// |value| ≤ flatBand reads as "no real change" — a declared noise floor
<TrendArrow value={0.01} flatBand={0.02} />
```

`flatBand` is where you declare your noise floor, so a ±0.1% wiggle reads as no change instead of a trend.

```tsx
<TrendArrow value={0.12} showValue format={{ style: "percent", maximumFractionDigits: 0 }} />
```

```tsx
<TrendArrow value={-0.08} positive="down" />
```

## Edge cases

```tsx
<TrendArrow value={0} showValue />
```

```tsx
<TrendArrow value={Number.NaN} showValue />
```

```tsx
<TrendArrow value={12483} showValue format={{ maximumFractionDigits: 0 }} locale="de-DE" />
```

`format`/`locale` reach `showValue`'s number and the accessible summary's magnitude together — "12,483" becomes "12.483"
in German grouping.

## Four homes

**In a sentence**

```tsx
<p>
  P95 latency{" "}
  <span className="mc-inline">
    <TrendArrow value={0.09} positive="down" format={{ style: "percent" }} summary={false} />
  </span>
  {" "}
  is up 9% since the deploy.
</p>
```

**In a table cell**

```tsx
<td>
  <TrendArrow value={-0.22} positive="down" format={{ style: "percent" }} />
</td>
```

**In a KPI card**

```tsx
<div className="kpi">
  <span className="figure">0.6%</span>
  <span className="unit">of requests</span>
  <TrendArrow value={-0.22} positive="down" showValue format={{ style: "percent" }} />
</div>
```

**In a tab header**

```tsx
<button className="tab">
  API <TrendArrow value={-0.08} positive="down" glyph="chevron" />
</button>
```

## Accessibility

The default accessible name is the direction: **"Up 12%."**, **"No change."** within the flat band, **"No data."** for
non-finite input. `positive="down"` flips only the color, never the glyph or the words. The interactive entry announces
direction changes through a polite live region and pulses the glyph, gated on reduced motion.

This chart is a single unit, so there is nothing to rove between: a click, tap, `Enter` or `Space` selects it
and fires `onSelect`, and no selection stays pinned. That is the scalar half of the shared
[interaction contract](/docs/accessibility#one-interaction-contract).

## Props

| Prop | Type | Description |
| --- | --- | --- |
| `value` (required) | `number` | Signed change; sign → direction, magnitude only via showValue/summary. |
| `flatBand` | `number` | Noise floor: \|value\| ≤ flatBand renders the flat glyph. |
| `glyph` | `"arrow" \| "triangle" \| "chevron"` | Mark weight: default legibility, dense cells, inline text. |
| `showValue` | `boolean` | Append the formatted value in a right gutter. |
| `positive` | `"up" \| "down"` | Which direction is good (colors only, never the glyph). |
| `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).
