Documentation / Charts
Sparkline
An axis-less line, read for its shape: the trend beside a figure, in a table cell or within a sentence. It does not anchor at zero and fits itself to its own values; two sparklines are therefore only comparable when they share a domain.
Without ariaLabel it stays out of the accessibility tree: beside a value, the value is what informs. Name it when it carries the information on its own. A null value breaks the line.
No hooks: the component renders on the server.
Examples
Basic usage
An array of numbers, in order; the default colour is the palette’s first slot.
import { Sparkline } from "@synertech/ui";
const revenue = [18, 21, 19, 26, 29, 27, 31, 35];
export function Basic() {
return <Sparkline data={revenue} width={160} height={36} />;
}Area and last point
area adds a wash under the line, emphasizeLast marks the current value.
import { Sparkline } from "@synertech/ui";
const revenue = [18, 21, 19, 26, 29, 27, 31, 35];
export function AreaAndLast() {
return (
<div className="flex items-center gap-6">
<Sparkline data={revenue} width={160} height={36} area emphasizeLast />
<Sparkline data={revenue} width={160} height={36} curve="step" strokeWidth={2} />
</div>
);
}In a sentence or a table
Inline with text, the sparkline stays decorative; on its own, it gets an ariaLabel.
import { Sparkline } from "@synertech/ui";
const revenue = [18, 21, 19, 26, 29, 27, 31, 35];
export function Inline() {
return (
<div className="flex flex-col gap-4 text-sm">
<p>
Le revenu passe de 18 k€ à 35 k€{" "}
<Sparkline data={revenue} width={64} height={16} className="inline-block align-middle" />{" "}
sur huit mois.
</p>
<Sparkline
data={[18, 21, null, 26, 29, 27, 31, 35]}
width={200}
height={40}
emphasizeLast
ariaLabel="Revenu mensuel sur huit mois, de 18 k€ à 35 k€, mars manquant"
/>
</div>
);
}API reference
Components
A small, axis-less line showing the shape of a series.
Unlike a chart, it does not anchor its scale at zero: a sparkline is read for its shape, and forcing a zero baseline flattens exactly the variation it exists to show.
No hooks, so it renders on the server and inside a table cell as happily as in a stat tile.
import { Sparkline } from "@synertech/ui";Props — SparklineProps
| Prop | Type | Default | Description |
|---|---|---|---|
data• |
readonly (number | null | undefined)[] |
— | Values in order. |
area |
boolean |
false |
Adds a wash under the line. |
ariaLabel |
string |
— | Names the sparkline for assistive technology. Left out, the sparkline is hidden from it: inside a stat tile the value beside it is the information, and a second reading of the same figure is noise. |
color |
string |
CHART_SERIES_COLORS[0] |
Any CSS colour. Defaults to the first palette slot. |
curve |
ChartCurve |
"monotone" |
|
domain |
[number, number] |
— | Fixes the bounds. Two sparklines only compare if they share a domain — without this, each one rescales to its own values. |
emphasizeLast |
boolean |
false |
Marks the current value with a dot. |
height |
number |
28 |
|
strokeWidth |
number |
2 |
|
width |
number |
96 |
+ 483 inherited native attributes from SVGAttributes, AriaAttributes, DOMAttributes (className, id, aria-*, event handlers…).