Sparkline
ProSmall trend charts: KPI tiles, a metric list, a column strip and a win/loss strip, plus SparklineMini for tables and tiles.
Playground
Sparklines
Installation
Sparkline comes with WunderUI Core and Pro, in the package from your plan. See the plans.
The charts live in their own entry point: import the chart, its card and its hooks from @wunderui/react/charts, not from @wunderui/react.
Then import what you need:
import {
Sparkline,
SparklineMetric,
SparklineMini,
SparklineMiniProps,
SparklineProps,
SparklineVariant,
} from "@wunderui/react/charts"Then use it:
import { SparklineMini } from "@wunderui/react/charts"
export function TrendCell() {
return <SparklineMini data={[48, 50, 49, 53, 55, 54, 58, 61]} aria-label="Up 27 % over 8 days" />
}Expected result: You see a small green trend line, 96 by 32 px, rising from left to right.
When to use
Use Sparkline for
- A trend next to a number in a KPI tile or a metric list
- A tiny trend in a table row (SparklineMini)
- A daily strip of columns, or a win and loss strip, in a card
Use something else for
- Line Chart for a trend with axes, a tooltip and a legend
- Area Chart for volumes that need an axis
- KPI for a single figure with a change
- Metric Card for a card with a figure, a chart and a menu
States
Loading shows placeholders in the box of the tiles, so the layout does not move. There is no empty or error state: show an empty state or an alert in its place.
Sparkline Mini
SparklineMini is the trend line for a table row, tile or list: 96 by 32 px, or fluid to fill its cell (drawn at its real width, so the end dot stays round), with no axes or tooltip. It draws in and ends on a dot, like the end point of a Line chart. Colour follows direction, and an aria-label should say what it shows.
Hover and new data
Hover a SparklineMini and the line steps back while a short window around the point keeps its strength, with a dot on the point — the spotlight of the Line chart. onActiveIndexChange hands you the point, for example to show its value next to the line. New data, such as another period, morphs the line from where it is in half a second instead of drawing it in again.
Trends
- MRR$34.1k
- Active users8,420
- Churn2.1%
Behavior and motion
What the sparkline draws and what it leaves to the page.
- Hover
- Sparklines take no focus and no keys; the accessible name carries the meaning, so write one that says what the trend is. The pointer follows the one hover model of the charts. SparklineMini dims the line and keeps a window around the hovered point, with a dot on it. The bar and win-loss strips keep the hovered bar at full strength (a pale bar comes up to full), dim the others to --chart-dim and show a compact tooltip beside the bar (labels name the values, tooltip={false} turns it off). Both hand the hovered index to onActiveIndexChange, for example to show its value next to the line.
- Formats
- KPI tiles and the metric list read metrics (label, value, change, points). The bar and win-loss strips read data, with height, colour and highlight options.
- Direction
- SparklineMini colours by direction (green up, red down, grey flat), and you can override it. The change in tiles and lists has a sign, so direction isn't only colour.
- End point and new data
- SparklineMini ends on a dot that arrives with the line (endPoint turns it off). New data morphs the line from where it is instead of drawing it in again; fluid draws at the cell's real width, so the dot stays round.
- Loading
- The loading state shows placeholders in the tiles' box, so the layout doesn't move when values arrive.
Motion
The enter sequence and the hover follow the library's motion tokens.
- Count and draw
- The number counts up to its value and the line draws in the first time the sparkline comes into view. You can turn it off.
- Reduced motion
- With reduced motion the enter sequence is off and the chart appears at once. Every state still works.
Anatomy
Sparkline covers the small trend formats: KPI tiles, a metric list, a column strip and a win/loss strip. SparklineMini is the 96 by 32 px trend line, with no axes or tooltip.
Sparklines
- 1data-slot="sparkline"
Picks a format: KPI tiles and a metric list read metrics (label, value, change, points), while the bar and win-loss strips read plain data. A loading state shows placeholders.
- Optional
The number, which counts up to its value, with the change under it (tiles) or beside it (list). It has a sign and a success or error colour, so direction isn't only colour.
- Optional
In the bar strip, one column per value with the highlighted bar solid and the rest pale. In the win-loss strip, green bars above the middle line and red below. The hovered bar keeps its strength and the others dim.
- data-slot="sparkline-end"Optional
- data-slot="sparkline-spotlight"Optional
- data-slot="sparkline-active"Optional
- 2data-slot="sparkline-mini"Optional
The trend line, as line or area, 96 by 32 px by default or fluid to fill its cell, coloured by direction (green up, red down, grey flat). Give it an aria-label like Up 12.4% over 7 days.
Best practices
- Do
Always put the current value and the change next to the line. The line has no scale, so the number carries the meaning.
- Do
Set an aria-label with the direction and period on every SparklineMini. Without it the label is generated from the first and last value.
- Do
Use the same number of points and period for every row of a list. A seven-day line beside a 30-day line cannot be compared.
- Don’t
Don't compare the heights of two sparklines. Each is scaled to its own minimum and maximum, so a flat series and a volatile one can look alike.
- Don’t
Don't use the win-loss strip for values that aren't a result of a period. Positive means a win and anything else a loss.
API reference
Two tables: Sparkline, the formats that pair numbers with a trend, and SparklineMini, the trend line of a table row or a tile. Both are plain components with their own props.
Picks a format: KPI tiles and a metric list read metrics (label, value, change, points), while the bar and win-loss strips read plain data. A loading state shows placeholders.
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "kpi-tiles" | "metric-list" | "bar-sparkline" | "win-loss-sparkline" | "kpi-tiles" | Figma variant. Default . |
| metrics | readonly SparklineMetric[] | [] | , : one metric per tile / row. |
| data | readonly number[] | [] | , : the values. |
| height | number | 48 | , : height of the strip (default 48). |
| color | "indigo" | "blue" | "purple" | "green" | "orange" | "pink" | "yellow" | "red" | "grey" | — | : colour of the bars (default indigo). |
| highlight | number | — | : the bar drawn solid (default the last one); the others are pale. |
| valueFormatter | (v) => string | (v) => String(v) | |
| label | string | "Sparkline" | |
| state | "ready" | "loading" | "empty" | "error" | "ready" | |
| labels | readonly string[] | — | Bar and win-loss strips: names of the values (days, weeks) for the tooltip title. Default "3 of 12". |
| tooltip | boolean | true | Bar and win-loss strips: the compact tooltip beside the hovered bar. Default true. |
| onActiveIndexChange | (index) => void | — | Bar and win-loss strips: called with the index of the hovered bar and with when the pointer leaves. Use it to show the hovered value in a headline. |
| animate | boolean | true |
The trend line, as line or area, 96 by 32 px by default or fluid to fill its cell, coloured by direction (green up, red down, grey flat). Give it an aria-label like Up 12.4% over 7 days.
| Prop | Type | Default | Description |
|---|---|---|---|
| data required | readonly (number | null | undefined)[] | — | |
| variant | "line" | "area" | "line" | or (Figma Sparkline Mini · Style). |
| trend | "auto" | "up" | "down" | "neutral" | "auto" | Colour by direction: compares first and last value (Figma · Trend). |
| color | "indigo" | "blue" | "purple" | "green" | "orange" | "pink" | "yellow" | "red" | "grey" | — | Override the trend colour (token or palette name). |
| fluid | boolean | false | Fill the parent's width (up to ) instead of a fixed size, for tiles and cards whose cells get narrow. The stroke keeps its weight. |
| width | number | 96 | Default 96 × 32 (Figma Sparkline Mini). |
| height | number | 32 | |
| animate | boolean | true | |
| aria-label | string | — | Accessible description, e.g. "Up 12 % over 7 days". |
| endPoint | boolean | true | A dot on the last value, like the end point of a Line chart. Default true. |
| onActiveIndexChange | (index) => void | — | Called with the hovered point (pointer only) and with null when the pointer leaves, e.g. to show its value next to the line. |
Notes for AI
Give your coding assistant the Markdown reference instead of screenshots.
get_component("sparkline")The full library index for assistants is at /llms.txt.
Related components
Line chart, 12 points from Jan to Dec. Revenue from $32.0k to $58.0k, lowest $32.0k, highest $58.0k; Expenses from $18.0k to $35.0k, lowest $18.0k, highest $38.0k. Revenue and expenses, data table month Revenue Expenses Jan $32.0k $18.0k Feb $41.0k $22.0k Mar $38.0k $27.0k Apr $47.0k $24.0k May $44.0k $30.0k Jun $52.0k $28.0k Jul $49.0k $34.0k Aug $55.0k $31.0k Sep $51.0k $36.0k Oct $46.0k $33.0k Nov $53.0k $38.0k Dec $58.0k $35.0k Charts27 stylesProLine ChartLine chart for trends over time: smooth lines (straight on request) and stepped lines, comparisons, bands, forecasts and thresholds, with tooltip, keyboard navigation and a data table.Area chart, 12 points from Jan to Dec. Revenue from $32.0k to $58.0k, lowest $32.0k, highest $58.0k; Expenses from $18.0k to $35.0k, lowest $18.0k, highest $38.0k. Area Charts, data table month Revenue Expenses Jan $32.0k $18.0k Feb $41.0k $22.0k Mar $38.0k $27.0k Apr $47.0k $24.0k May $44.0k $30.0k Jun $52.0k $28.0k Jul $49.0k $34.0k Aug $55.0k $31.0k Sep $51.0k $36.0k Oct $46.0k $33.0k Nov $53.0k $38.0k Dec $58.0k $35.0k Charts19 stylesProArea ChartArea chart for volumes over time: gradients, steps, ranges, a horizon graph, differences and target lines.