Quire UI
Charts10

Sparkline

A small trend with no axes, for beside a figure, in a table row or a card. Read any point by pointer, touch or keyboard. No chart library.

October

$50,065

Installation

npx shadcn@latest add @quireui/sparkline

Usage

<Sparkline label="Revenue in October" data={[1320, 1410, 1385, 1490, 1560]} className="h-12 w-40" />

It fills the box you give it, so its size is a class. data takes numbers, or { label, value } to name each point, which is what screen readers hear and what synced sparklines match on.

Reading a point

Point at it, touch it or arrow along it, and onActiveChange reports the point being read, so the figure beside it can show that point. Let go and it reports null, for the total to come back. With active you control it, and several sparklines can follow one cursor. Moving up and down on a touch screen still scrolls the page.

const [active, setActive] = useState<string | null>(null);
const point = revenue.find((item) => item.label === active);

<p>{money.format(point ? point.value : total)}</p>
<Sparkline label="Revenue in October" data={revenue} active={active} onActiveChange={setActive} />

Lines, bars and steps

type="bars" suits counts per day and stands on zero; a line zooms in on its own range, which suits a level that moves. curve is the same as on the Chart: smooth never overshoots the data, and step holds each value until the next. previous draws the period before dashed behind it, and partial marks a last point that is still being counted.

Smooth, with the month before

Bars, for counts

Steps, for a seat count

Today still being counted

Colour

It is a quiet grey by default, so the figure beside it stays the loudest thing. color="trend" turns it green or red by where it ended against where it started, leaving out a last point still being counted; lowerIsBetter turns that around for latency or churn. Any CSS colour works too, like var(--qui-chart-1).

In a table

interactive={false} keeps it a picture: no tab stop, no handlers, and screen readers hear its name and its last point. That suits a table with a sparkline on every row, where fifty tab stops would be in the way.

Accessibility

Interactive, it is a slider over the points: screen readers hear its name and the point it is on, like "Oct 12: $1,490". valueText changes what they hear. Not interactive, it is an image named by label and its last point.

KeyAction
← / →, ↓ / ↑Previous or next point
PageDown / PageUpBack or forward a tenth
Home / EndFirst or last point
EscLets go of the point

Motion

Small and once. It rises into place when it first scrolls into view, and glides to new numbers when they arrive. Reading a point follows the pointer without easing; only the dot fades in. From the keyboard nothing waits, with reduced motion only the fades remain, and animate={false} turns the arrival and the gliding off.

Sparkline or something else?

  • One figure with its change and a sparkline, in a card: a Stat card, which is built on this.
  • A trend that needs its scale, dates or several series: a Chart.

API reference

Sparkline

A small trend with no axes, beside a figure, in a table row or a card. Point at it, touch it or arrow along it to read any point; several can follow one cursor.

Prop

Type

Also takes every <div> attribute. Style it with [data-slot="sparkline"].

On this page