# Combo chart

> Every day as a bar and the trend as a line on one scale: point at a day and the header becomes its readout while the line’s dot pings where it lands.

Daily numbers are noisy and a trend line is what people actually read, so this card draws both on one scale: thin bars for every day and a rolling average across them, never two axes that make the line mean something different. The first time it scrolls into view the bars grow out of the baseline in a wave and the average draws itself over them. Point at a day and its bar fills while the others dim, the line’s dot slides along and pings once where it lands, and the header becomes the readout: the title morphs to "Orders on Thursday 2 October", the total rolls to that day’s count and the line below to its average. Beneath, the best day, the daily average and the quietest day roll up as tiles.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/combo-chart.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: none
- Hairline UI components it needs (the CLI installs them too): `number-roll`, `text-morph`
- Docs and live preview: https://hairlineui.com/ui/combo-chart
- Registry item (source): https://hairlineui.com/r/combo-chart.json

## Usage

```tsx
import { ComboChart } from "@/components/combo-chart";

<ComboChart
  title="Orders"
  days={lastThirtyDays} // [{ key: "2026-10-02", label: "2 Oct", value: 126 }, …]
  previous={3212}
/>
```

## From your database

Count by day on the server. Pass your own average if it should include the days before the first bar, so the line starts settled.

```tsx
import { ComboChart } from "@/components/combo-chart";
import { db } from "@/lib/db";

export async function DailyOrders() {
  const rows = await db.ordersByDay({ days: 36 }); // six extra days to settle the average
  const average = rows.map((_, i) => rows.slice(Math.max(0, i - 6), i + 1).reduce((s, r) => s + r.count, 0) / Math.min(7, i + 1));
  const days = rows.slice(6).map((r) => ({
    key: r.day,
    label: new Date(r.day).toLocaleDateString("en-GB", { day: "numeric", month: "short" }),
    title: new Date(r.day).toLocaleDateString("en-GB", { weekday: "long", day: "numeric", month: "long" }),
    value: r.count,
  }));
  return <ComboChart title="Orders" days={days} average={average.slice(6)} previous={await db.ordersBetween("-60d", "-30d")} />;
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `days` | `ComboDay[]` | – | Oldest first, each { key, label, value, title? }. |
| `rolling` | `number` | `7` | The line is a rolling average over this many days (fewer at the start). |
| `average` | `number[]` | – | Your own line values instead, one per day. |
| `previous` | `number` | – | The total of the period before, for the change chip. |
| `series` | `[string, string]` | `["Orders", "7-day average"]` | The bars’ and the line’s names, in the legend and readout. |
| `title` | `string` | `"Orders"` | Above the total, and in the readout. |
| `format` | `Intl.NumberFormatOptions` | – | How figures read (whole numbers by default). |
| `locales` | `string \| string[]` | – | For number formatting. |

## States

- **arrive**: In view for the first time, each bar grows from the baseline (640ms, 14ms apart) and the average is revealed from left to right after them (1100ms); every figure rolls up from zero.
- **hover**: The bar under the pointer goes to full strength and the rest dim; the line’s dot glides to that day (260ms, slight overshoot) and a ring pings out from it once (640ms). The title morphs to "<title> on <day>", the total and average roll to the day and the change chip folds away until you leave.
- **tiles**: Best day, daily average and quietest day, each with its date or span, roll up on arrival.

## What it handles

Daily numbers are noisy, and the trend is what people actually read. Charting both usually means a chart library, a second axis that confuses people, and a tooltip. This draws both on one scale.

- **Bars and trend on one scale**: Every day is a bar and the average is a line over them. There is only one axis, so the line never means something different.
- **The rolling average is built in**: A 7-day average by default, or pass your own line values.
- **Point at a day**: The header becomes the readout: that day’s title, total and average, rolling to the new numbers.
- **Best, average and quietest**: Three tiles under the chart show the best day, the daily average and the quietest day.
- **Change since last period**: Pass the previous total and a chip shows the change.
- **Keyboard and a hidden table**: Arrow keys move between days, and every day is also in a visually hidden table.

## Replaces

a chart library, rolling average maths, a hover tooltip, a stats row, a data table for screen readers

## Where it fits

- **Orders and sales**: A bar for every day of sales, with the trend running over them.
- **Signups and traffic**: Daily visitors with a 7-day average that smooths out the noise.
- **Support volume**: Tickets per day, so a spike stands out against the usual level.
- **API and app usage**: Daily requests or active users in a usage dashboard.

## Notes

- Grey in a new shadcn project? Its default theme sets --chart-1 to --chart-5 to greys. Set five colours, light and dark, as in Theming › Chart colours (/ui/theming#charts).
- One scale for both marks, by design: a second axis would make the line’s height mean something different from the bars’.
- The plot is one tab stop: arrow keys, Home and End move between days and the day’s count and average are announced.
- The legend draws a bar and a line key, so the two marks are told apart by shape as well as colour; every day is in a visually hidden table.
- Bars use --chart-1 and the line --chart-2 from your theme.
- Installs Number roll and Text morph. With reduced motion nothing grows or pings.

License: MIT (https://hairlineui.com/license#components)
