# Bar chart

Amounts compared by length: a total per row, named things side by side, parts of a whole, a spread, a funnel.

Live variants: https://design.arcadia.is/components/bar-chart

```tsx
import { Bars } from "@arcadia/ui/charts";
```

## When to use

- A total for each day, each bar an amount of its own
- Named things compared by length, sorted by value
- Parts of a whole, bins of a spread, or steps of a funnel

## When not to use

- How much of a limit is left: use `Meter`
- Values a person looks up or copies: use `Table`
- A measure that varies between its rows over time: use `Line`

## In context

In Arcadia's products, bars compare amounts by length in a block of their own: a day's total, the size of each named thing, the parts of a whole.

A month of tokens per day, each day its own total. Point at a day, tap it or use the arrows to read it.

```tsx
import {
  Bars, Chart, Grid, Readout, XAxis, YAxis, chartColor,
} from "@arcadia/ui/charts";

<Chart label="Tokens per day" x={DAYS} size="lg">
  <Grid />
  <YAxis />
  <XAxis />
  <Bars label="Tokens" values={TOKENS} color={chartColor(1)} />
  <Readout />
</Chart>
```

## Usage

```tsx
import {
  Bars, Chart, Grid, Readout, XAxis, YAxis, chartColor,
} from "@arcadia/ui/charts";

<Chart label="Tokens per day" x={["2026-10-01", "2026-10-02", "2026-10-03"]}>
  <Grid />
  <YAxis />
  <XAxis />
  <Bars label="Tokens" values={[31_048_123, 33_454_961, 29_775_967]} color={chartColor(1)} />
  <Readout />
</Chart>
```

Bars show amounts you compare by length: a total for each day, the size of each named thing, the parts of a whole, how values spread over equal bins, how many get through each step. They always start at zero, because the bar's length is the value.

Over time, use bars when each row is a total of its own, such as tokens a day, and a line for a measure that varies between its rows. To compare named things, sort them and lay them on their side past eight names or when the names are long. Never a pie, never bars in no order, and never more than three bars to a group.

## Anatomy

- Band: One to a row, its bar centred in it: a quarter of the band is the gap between neighbours.
- Bar: At most 48px wide, with a 4px cap at the exposed end. The baseline and the joins in a stack stay flat.
- Zero and missing: A zero keeps a 1px sliver on the baseline, so the row reads as measured; a missing value draws nothing.
- Groups: Up to three series side by side in each band, 2px apart, in the legend's order.
- Stacks: Parts of a whole on one bar, the largest at the base; only the stack's far end is rounded.
- Signed: One colour above and below the solid zero rule, which stays visible between the two signs; under zero a bar's rounded end points down.
- Value labels: Caption in `--text-2`, beyond each bar's far end and never inside it: text on a series colour does not hold 4.5:1 in both themes.
- Horizontal: Names at the inline start, end-aligned and fading at their end when long; each bar runs to the inline end with its value beyond it, and the plot draws no grid.

## Examples

### Comparing named things

`horizontal` lays the bars on their side: names at the inline start in the order given, each bar labelled at its end. The labels are the scale, so the plot draws no grid.

Errors this week by service, largest first.

```tsx
import { Bars, Chart, Readout, XAxis, chartColor } from "@arcadia/ui/charts";

<Chart label="Errors this week by service" x={SERVICES} noun={["service", "services"]} size="lg">
  <XAxis />
  <Bars horizontal label="Errors" values={ERRORS} color={chartColor(1)} />
  <Readout />
</Chart>
```

### Grouped

Up to three series side by side in each band, 2px apart. The legend names each one, and the card reads them all on a row.

```tsx
import {
  Bars, Chart, Grid, Legend, Readout, XAxis, YAxis, chartColor,
} from "@arcadia/ui/charts";

<Chart label="Requests per second by month" x={HALF}>
  <Legend />
  <Grid />
  <YAxis />
  <XAxis />
  <Bars label="Europe" values={MONTHLY.europe} color={chartColor(1)} />
  <Bars label="Americas" values={MONTHLY.americas} color={chartColor(2)} />
  <Bars label="Asia" values={MONTHLY.asia} color={chartColor(3)} />
  <Readout />
</Chart>
```

### Stacked

`stacked` puts the parts of a whole on one bar, the largest at the base and leading the legend. Only the stack's far end is rounded, and the card adds the total.

```tsx
import {
  Bars, Chart, Grid, Legend, Readout, XAxis, YAxis, chartColor,
} from "@arcadia/ui/charts";

<Chart label="Requests per second by week" x={WEEKS.slice(4)}>
  <Legend />
  <Grid />
  <YAxis />
  <XAxis />
  <Bars stacked label="Europe" values={WEEKLY_RATE.europe} color={chartColor(1)} />
  <Bars stacked label="Americas" values={WEEKLY_RATE.americas} color={chartColor(2)} />
  <Bars stacked label="Asia" values={WEEKLY_RATE.asia} color={chartColor(3)} />
  <Readout />
</Chart>
```

### Signed around zero

Bars above and below the solid zero rule keep their one colour: the sign is the bar's side, never its colour. Under zero a bar rounds its lower end.

```tsx
import {
  Bars, Chart, Grid, Readout, XAxis, YAxis, chartColor,
} from "@arcadia/ui/charts";

<Chart label="Net change in seats per day" x={DAYS}>
  <Grid />
  <YAxis />
  <XAxis />
  <Bars label="Seats" values={NET} color={chartColor(1)} />
  <Readout />
</Chart>
```

### Value labels

`labels` writes each value beyond its bar's far end, never inside it. A series shows all its labels or none: they leave together as soon as one would crowd its neighbour.

On a narrow screen the labels leave as one, and the value axis keeps the scale.

```tsx
import {
  Bars, Chart, Grid, Readout, XAxis, YAxis, chartColor,
} from "@arcadia/ui/charts";

<Chart label="Releases per month" x={MONTHS}>
  <Grid />
  <YAxis />
  <XAxis />
  <Bars labels label="Releases" values={RELEASES} color={chartColor(1)} />
  <Readout />
</Chart>
```

### Dense

Many rows make narrow bars. Where a band would fall under 4px, bin the rows to the next coarser period before they reach the chart.

- 56 daily bars
- The same days binned to weeks

### A spread over equal bins

Each bar counts one bin, and its label names the bin.

```tsx
import {
  Bars, Chart, Grid, Readout, XAxis, YAxis, chartColor,
} from "@arcadia/ui/charts";

<Chart label="Requests by response time in ms" x={LATENCY_BINS} noun={["bin", "bins"]}>
  <Grid />
  <YAxis />
  <XAxis />
  <Bars label="Requests" values={SPREAD} color={chartColor(1)} />
  <Readout />
</Chart>
```

### A ranked share

Parts of a whole ranked by share, six and Other at most. `format` writes each label and the reading's value, here as a percent.

```tsx
import { fmtPercent } from "@arcadia/ui";
import { Bars, Chart, Readout, XAxis, chartColor } from "@arcadia/ui/charts";

<Chart label="Storage by kind" x={KINDS} noun={["kind", "kinds"]}>
  <XAxis />
  <Bars horizontal label="Share" values={SHARES} color={chartColor(1)} format={fmtPercent} />
  <Readout />
</Chart>
```

### A funnel

How many get through each step: horizontal bars in step order and one colour, each labelled with its value and its share of the first step, and the drop written between each pair with `between`.

Four steps from a visit to a subscription.

```tsx
import { fmtCount, fmtPercent } from "@arcadia/ui";
import { Bars, Chart, Readout, XAxis, chartColor } from "@arcadia/ui/charts";

function Funnel() {
  const share = (v: number) => `${fmtCount(v)} (${fmtPercent(v / PEOPLE[0]!)})`;
  const drops = PEOPLE.slice(1).map((v, i) => `${fmtCount(PEOPLE[i]! - v)} dropped, ${fmtPercent(1 - v / PEOPLE[i]!)}`);
  return (
    <Chart label="People through each step" x={STEPS} noun={["step", "steps"]} rootStyle={s.steps}>
      <XAxis />
      <Bars horizontal label="People" values={PEOPLE} color={chartColor(1)} format={share} between={drops} />
      <Readout />
    </Chart>
  );
}
```

## Reading

`Readout` reads a band with the pointer, a finger or the keys, as on the other charts.

The pointer reads the band under it. That column stays whole in the pointer's own frame and the others set back to `--chart-dim` over `--duration-fast`. There is no crosshair and no dot: the column that stays is the mark. The axis chip names the row, and the card stands 16px from the column's edge, turning to the other side where it would leave the plot.

On a horizontal chart the reading runs down the rows. A card sits under the read row at the plot's far end, or over it near the bottom, and the keys follow the rows.

Where the card would only repeat the read bar's value label, one series whose label already prints the card's value, no card is drawn: the label steps up to `--text-1` and the bar is the reading. Several series and a stack's total keep the card, as do labels in a compact form and labels a narrow plot has dropped.

- Tab: Moves to the plot: the reading starts on the newest row (the top one on a horizontal chart), or on the row read last.
- ↑ + ↓: Step a row as on any slider: Up to the next, or on a horizontal chart to the row above.
- ← + →: Step a row: Right to the next, or on a horizontal chart to the row above.
- Home + End: The first row and the last, or on a horizontal chart the bottom row and the top.
- Esc: Hides the reading until the next key.

## States

### Zero, missing and one bar

A zero keeps a 1px sliver on the baseline; a missing value draws nothing and reads No data; one row is one bar in the middle of the plot.

- Zero on two days
- No count on September 9
- One row

### In progress

`partialLast` draws the last bar lighter, with a dashed edge, while its period runs. On a total, `pace` keeps the count so far solid and adds a dashed cap at the rate so far.

```tsx
import {
  Bars, Chart, Grid, Readout, XAxis, YAxis, chartColor,
} from "@arcadia/ui/charts";

<Chart label="Tokens per day" x={DAYS.slice(-14)} partialLast={{ elapsed: 0.45 }}>
  <Grid />
  <YAxis />
  <XAxis />
  <Bars pace label="Tokens" values={SO_FAR} color={chartColor(1)} />
  <Readout />
</Chart>
```

- `partialLast`: the count so far
- `pace`, 11 hours into the day

### Too many rows

Where a band would fall under 4px, bin the rows to a coarser period before they reach the chart and say so in its label, per week instead of per day: `Bars` draws every row it is given.

## Accessibility

A bar chart is named from its data like any other: "Tokens per day: 30 days, from 27.5M to 36.8M, up 34%". A stack adds its total, and each series of a group adds its own first and last value.

Rows that are names have no order to change along, so the name gives their count, the highest and the lowest by name, and no change: "Errors this week by service: 8 services, most Search 1,284, least Webhooks 96". `noun` gives the chart its word for a row; without it they are rows.

With `Readout` the plot is a slider over its rows, and its value text reads the row the way the card does: "Tue, Oct 6: Tokens 36,771,405". A horizontal chart is a vertical slider whose value runs from its bottom row up to its top one, so Up and Right step to the row above. Its value text uses `format`, so the share chart reads "Images: Share 34%".

Value labels and the funnel's drops are drawn for the eye; the name and the value text carry the same numbers, the drops as the difference between two rows.

With `partialLast` the name compares complete rows only, so a day still counting is never heard as a drop. On that row the value text says so and, with `pace`, adds the rate so far: "Tue, Oct 6, in progress, 11h elapsed: Tokens 14,918,402, pace 33,152,004".

## API reference

### Bars

- `stacked` (`boolean`): On the other stacked bars, the largest at the base.
- `horizontal` (`boolean`): Rows run down the plot, each bar labelled at its end.
- `labels` (`boolean`): Each value beyond its bar's end. Always on a horizontal chart.
- `format` (`(value: number) => string`): How a value reads on its label and in the reading.
- `between` (`readonly (string | null | undefined)[]`): Horizontal: a line between each bar and the next.
- `pace` (`boolean`)
- `label` (`string`, required): The series' name.
- `values` (`readonly (number | null | undefined)[]`, required): A value per row of `x`; `null` is a gap.
- `color` (`string`, required): The paint of the slot its entity owns: `chartColor(1)`.
- `appearance` (`"compact"`): A 1.5px square-cornered line (and, for an area, a flat, faint wash) for a compact summary beside its figures.
