Skip to content

Sparkline

ChartsSince 0.3.0

A word-sized trend graphic (line or bars) for text, table cells, and KPI tiles. It is a static image (role="img") whose generated accessible name summarizes the data: label, value count, first and last value, minimum, and maximum. It is not focusable and has no tooltip; creating one needs no layout reads, so hundreds per page are cheap. It does not use the chart frame, so importing it does not pull in Line, Bar, or Pie chart code.

  • Word-sized trendA small line or bar graphic for text, table cells, and KPI tiles.
  • Generated nameThe accessible name summarizes count, first, last, minimum, and maximum values.
  • Cheap at scaleNo layout reads on creation, so hundreds per page stay fast.
  • Last value markerHighlights the most recent value by default.

Use it for

  • Showing the shape of a trend next to a number (KPI tiles, table cells, sentences).
  • Many small trends on one page (cheap to create, no layout reads).

Use something else for

  • When users need to read individual values: use Line Chart or Bar Chart (tooltips, keyboard, data table).
  • As the only source of important information.
Anatomy
<span class="aui-sparkline aui-sparkline--line aui-sparkline--c1">
<svg class="aui-sparkline__svg" role="img" aria-label="Weekly sign-ups: 12 values, from 120 to 230, minimum 120, maximum 230." viewBox="0 0 100 24" preserveAspectRatio="none">
<path class="aui-sparkline__line"/> <path class="aui-sparkline__last"/> (line)
<rect class="aui-sparkline__bar [aui-sparkline__bar--last]"/> <path class="aui-sparkline__baseline"/> (bar)
</svg>
</span>

Use the bar above each frame to switch theme, density, direction, and locale.

The part of the Sales report showcase that uses Sparkline. Change its options, use it with the keyboard, and watch the event log; the link in the frame opens the full showcase. The bar above the frame switches theme, density, direction, and locale.

Showcase source
// Basic charts showcase: a sales report with a line chart (zoom, a dashed plan series, a target
// band), grouped or stacked bars (reference line, zoom), a donut, a bar chart whose crosshair is
// synchronized with the trend, sparklines, and SVG or PNG export. Legend, data table, patterns,
// style, and animation are switchable; point clicks are logged.
import { BarChart } from '@absoluteui/components/bar-chart';
import { downloadChart } from '@absoluteui/components/chart-export';
import { LineChart } from '@absoluteui/components/line-chart';
import { PieChart } from '@absoluteui/components/pie-chart';
import { Sparkline } from '@absoluteui/components/sparkline';
import { action, chartControls, chartLook, choice, createShowcase, hostIn, section, toggle } from './kit.js';
const sc = createShowcase({
title: 'Sales report',
description: 'Hover or use the arrow keys on a chart for values (the trend and the orders chart follow each other), click or press Enter on a point, toggle series in the legend, change the style, zoom, and export a chart.',
});
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const wave = (base: number, amp: number, phase: number): number[] => MONTHS.map((_, i) => Math.round(base + amp * Math.sin(i / 2 + phase) + i * 4));
const eur = { style: 'currency', currency: 'EUR', notation: 'compact' } as const;
const trend = section(sc, 'Monthly revenue', ['line-chart', 'bar-chart']);
const line = LineChart.create(hostIn(trend), {
label: 'Monthly revenue by region',
description: 'Thousands of euros, 2026.',
x: MONTHS,
series: [
{ id: 'emea', label: 'EMEA', values: wave(120, 18, 0) },
{ id: 'apac', label: 'APAC', values: wave(90, 22, 1) },
{ id: 'amer', label: 'Americas', values: wave(150, 15, 2) },
{ id: 'plan', label: 'Plan (Americas)', values: MONTHS.map((_, i) => 150 + i * 5), style: { dash: 'dashed', marker: 'none', lineWidth: 1.5 } },
],
valueFormat: { ...eur, maximumFractionDigits: 0 },
annotations: [{ type: 'band', axis: 'x', from: 'Jun', to: 'Aug', label: 'Summer campaign', tone: 'info' }],
zoom: true,
crosshair: true,
syncGroup: 'sales-months',
height: 280,
});
const orders = BarChart.create(hostIn(trend), {
label: 'Orders by month',
description: 'Hover or focus either chart: both show the same month.',
categories: MONTHS,
series: [{ id: 'orders', label: 'Orders', values: MONTHS.map((_, i) => 300 + Math.round(60 * Math.sin(i / 2)) + i * 12) }],
syncGroup: 'sales-months',
height: 200,
});
const grid = hostIn(sc.stage);
grid.className = 'sc-grid';
const quarter = section(sc, 'Revenue by quarter', ['bar-chart']);
const mix = section(sc, 'Product mix', ['pie-chart']);
grid.append(quarter, mix);
const bars = BarChart.create(hostIn(quarter), {
label: 'Revenue by quarter',
categories: ['Q1', 'Q2', 'Q3', 'Q4'],
series: [
{ id: 'licenses', label: 'Licenses', values: [310, 340, 365, 420] },
{ id: 'services', label: 'Services', values: [120, 135, 150, 160] },
],
valueFormat: { ...eur, maximumFractionDigits: 0 },
annotations: [{ type: 'line', axis: 'y', value: 400, label: 'Target', tone: 'success' }],
height: 260,
});
const pie = PieChart.create(hostIn(mix), {
label: 'Product mix',
slices: [
{ id: 'core', label: 'Core', value: 48 },
{ id: 'analytics', label: 'Analytics', value: 27 },
{ id: 'support', label: 'Support plans', value: 15 },
{ id: 'training', label: 'Training', value: 10 },
],
donut: true,
centerLabel: 'Share',
valueFormat: { style: 'percent', maximumFractionDigits: 0 },
height: 260,
});
const minis = section(sc, 'Sparklines', ['sparkline']);
const row = hostIn(minis);
row.className = 'sc-row';
const signups = Sparkline.create(hostIn(row), { label: 'Daily sign-ups', values: [12, 18, 15, 22, 30, 28, 35, 33, 41], variant: 'line', color: 1 });
const refunds = Sparkline.create(hostIn(row), { label: 'Daily refunds', values: [4, 3, 6, 2, 5, 3, 2, 1, 2], variant: 'bar', color: 2 });
sc.listen(line.host, ['aui-series-toggle', 'aui-zoom', 'aui-point-click'], 'line');
sc.listen(orders.host, ['aui-point-click'], 'orders');
sc.listen(bars.host, ['aui-series-toggle', 'aui-zoom', 'aui-point-click'], 'bars');
sc.listen(pie.host, ['aui-series-toggle', 'aui-point-click'], 'pie');
chartControls(sc, [line, orders, bars, pie], ['line-chart', 'bar-chart', 'pie-chart']);
chartLook(sc, [line, orders, bars, pie, signups, refunds]);
choice(
sc,
'Bars',
[
{ value: 'grouped', label: 'Grouped' },
{ value: 'stacked', label: 'Stacked' },
],
'grouped',
(layout) => {
bars.update({ layout });
},
['bar-chart'],
);
toggle(sc, 'Horizontal bars', false, (horizontal) => {
bars.update({ orientation: horizontal ? 'horizontal' : 'vertical' });
}, ['bar-chart']);
toggle(sc, 'Zoom the orders chart', false, (zoom) => {
orders.update({ zoom });
}, ['bar-chart']);
toggle(sc, 'Area under lines', false, (area) => {
line.update({ area });
}, ['line-chart']);
action(sc, 'Export trend (SVG)', () => {
void downloadChart(line, { format: 'svg', fileName: 'monthly-revenue.svg' });
}, ['line-chart']);
action(sc, 'Export mix (PNG)', () => {
void downloadChart(pie, { format: 'png', fileName: 'product-mix.png' });
}, ['pie-chart']);
import { Sparkline } from '@absoluteui/components/sparkline';
const host = document.createElement('span');
document.body.append(host);
Sparkline.create(host, { label: 'Weekly sign-ups, last 12 weeks', values: [120, 132, 128, 150, 149, 170, 181, 176, 195, 210, 205, 230] });

Bar sparkline with negatives and a fixed domain

Section titled “Bar sparkline with negatives and a fixed domain”
import { Sparkline } from '@absoluteui/components/sparkline';
const host = document.querySelector<HTMLElement>('#net');
if (host) {
const spark = Sparkline.create(host, { label: 'Net change per day', values: [4, -2, 6, null, -5, 8], variant: 'bar', color: 3, min: -10, max: 10 });
spark.update({ values: [4, -2, 6, 3, -5, 8] });
}
Terminal window
npm install @absoluteui/components @absoluteui/core @absoluteui/theme

Registry setup, the theme stylesheet, and the Content Security Policy are covered in Installation.

import { Sparkline } from '@absoluteui/components/sparkline';
import '@absoluteui/components/sparkline/style.css';
import { Sparkline } from '@absoluteui/components/sparkline';
import '@absoluteui/components/sparkline/style.css';
for (const cell of document.querySelectorAll<HTMLElement>('[data-trend]')) {
const values = (cell.dataset.trend ?? '').split(',').map(Number);
Sparkline.create(cell, { label: cell.dataset.label ?? 'Trend', values, variant: 'bar' });
}
More usage
import { Sparkline } from '@absoluteui/components/sparkline';
const host = document.createElement('span');
document.body.append(host);
Sparkline.create(host, { label: 'Weekly sign-ups', values: [120, 132, 150, 170] });

Using Angular? See Sparkline for Angular.

Sparkline.create(host: HTMLElement, options: SparklineOptions): Sparkline

Global configuration key: sparkline (see Configuration).

Option Type Default Description
label string What the values are, for example “Revenue, last 12 months”; starts the accessible name. Required.
values readonly (number | null)[] Values in order; null, NaN, and infinities are gaps. Required.
variant 'line' | 'bar' "line" Line or bars (bars include zero and draw negatives below a baseline).
color 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 1 Palette slot (color-chart-<n>).
min number Fixed domain minimum (for comparable sparklines).
max number Fixed domain maximum.
valueFormat Intl.NumberFormatOptions Number format for the accessible name.
formatValue (value: number) => string Custom value text for the accessible name.
valueText string Replaces the generated accessible name.
theme ChartTheme Look and feel: { palette?: string[] (1-8 CSS colors for slots 1-8); fontFamily?; fontSize? (8-32 px); textColor?; gridLines?: boolean; gridColor?; gridDash? (“4 2” or “none”); axisColor?; lineWidth? (0.5-12 px); markerSize? (1-20 px); cornerRadius?, barRadius?, cellRadius?, sliceRadius?, boxRadius? (0-50 px); swatchRadius? (0-8 px); tooltipRadius?, controlRadius? (0-50 px); lineJoin?: ‘round’ | ‘miter’ | ‘bevel’; areaOpacity? (0-1); gradient?: boolean; valueLabelColor?; tooltip?: { background?, color?, borderColor? }; legendPosition?: ‘top’ | ‘bottom’ | ‘start’ | ‘end’; animation?: boolean | { duration?: number (0-5000 ms) } }. Applied as –aui-chart-* custom properties and classes on the host through the CSSOM (CSP-safe); colors are validated with CSS.supports(‘color’). Animation is opt-in and never runs with prefers-reduced-motion: reduce or [data-aui-animation=‘none’]. The sparkline uses palette, lineWidth, axisColor (bar baseline), and animation.
highlightLast boolean true Mark the last value (dot for line, full opacity for bar). Globally configurable.
locale string "en-US" Number, date, and message locale. Globally configurable. Inherited from common configuration.
direction 'ltr' | 'rtl' "ltr" rtl mirrors the category/x axis, the value axis side, and Left/Right arrow keys. Globally configurable. Inherited from common configuration.
Property Type Description
host HTMLElement The host element.
element SVGSVGElement The svg role=“img”.
summary string The accessible name (generated or valueText).
Method Description
update(options: Partial<SparklineOptions>): void Merge, validate, and re-render.
destroy(): void Remove rendering, classes, and the configuration subscription.

All rules live in the aui.components cascade layer, so application styles override them without specificity battles.

Class Purpose
aui-sparkline Host; inline-block, 6em x 1.5em by default (set inline-size / block-size to resize).
aui-sparkline--line / --bar Variant modifiers.
aui-sparkline--c1 ... --c8 Palette slot; sets –aui-sparkline-color.
aui-sparkline__svg / __line / __dot / __last / __bar / __bar--last / __baseline SVG and its parts (non-scaling strokes).

Tokens this stylesheet reads (verified in CI). Override them in a theme or with the Theme Designer.

--aui-color-chart-1 | --aui-color-chart-2 | --aui-color-chart-3 | --aui-color-chart-4 | --aui-color-chart-5 | --aui-color-chart-6 | --aui-color-chart-7 | --aui-color-chart-8 | --aui-color-chart-axis | --aui-easing-standard

TypeScript definitions
interface SparklineConfig { highlightLast: boolean }
interface SparklineOptions extends Partial<SparklineConfig> {
label: string;
values: readonly (number | null)[];
variant?: 'line' | 'bar';
color?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
min?: number;
max?: number;
valueFormat?: Intl.NumberFormatOptions;
formatValue?: (value: number) => string;
valueText?: string;
locale?: string;
direction?: 'ltr' | 'rtl';
}

Pattern: Static informative image: svg role=“img” with a generated accessible name (WAI Images tutorial, informative images).

Checked on every docs build: the showcase passes axe (WCAG 2.2 A and AA rules) in the default, dark, and high-contrast themes and right to left; the playground loads without errors and passes axe before and after every on/off option is switched, with no Content Security Policy violations.

Key Context Action
None Any Not focusable; the accessible name carries the summary. Use Line Chart for keyboard exploration.
Element Role
svg.aui-sparkline__svg img
Attribute Element Value
aria-label svg Localized “{label}: {count} values, from {first} to {last}, minimum {min}, maximum {max}.” (or valueText)

Not focusable.

Criterion Level Note
1.1.1 Non-text Content A
1.4.1 Use of Color A
1.4.11 Non-text Contrast AA
4.1.2 Name, Role, Value A

Automated test results: Accessibility and compliance.

  • Meaning is carried by the accessible name and the surrounding text, not by color.
  • Forced colors draw the sparkline in CanvasText.
  • No animation.
  • Individual values are not exposed; keep the key value in visible text next to the sparkline.
  • Manual screen-reader verification is pending.
Import cost Minified gzip brotli CSS brotli
@absoluteui/components/sparkline 19.2 kB 7.3 kB 6.5 kB 0.6 kB

Measured at build time, including every AbsoluteUI module the component pulls in. No third-party runtime dependencies.

Budget (enforced in CI) Limit
Sparkline.create, 30 values, per instance (average of 200) < 1 ms in headless Chromium (e2e performance test)

Tested scale: Hundreds of instances per page; one to a few hundred values each (bars create one rect per value).

Budget: under 1 ms per instance (30 values; e2e performance test, average of 200). No layout reads and no resize observer.

Measured run times: Performance.

States

line, bar, empty (“{label}: no data.”), single value (“{label}: {value}.”).

State transitions
From Trigger To
any update({ values }) re-rendered, new accessible name
line update({ variant: 'bar' }) bars
Accessibility notes
  • Keep the key value in visible text next to the sparkline; individual values are not exposed.
  • Meaning is carried by the accessible name and surrounding text, not by color.
  • Forced colors draw it in CanvasText. No animation.
  • Manual screen-reader verification is pending.
Responsive behavior

Scales with its box through the viewBox (preserveAspectRatio="none", non-scaling strokes). The default size is in em, so it follows the text size.

Right-to-left

direction: 'rtl' puts the first value at the right.

Theming

Stroke and bars use color-chart-<color> (3:1 against surfaces in all themes); the zero baseline uses color-chart-axis.

Global configuration
configureAbsoluteUI({ components: { sparkline: { highlightLast: false } } });
Component configuration

Instance options override global and theme defaults. All options are dynamic.

Security

The accessible name is an attribute value; SVG is built with createElementNS. No innerHTML or style attributes.

Data handling

No persistence, network access, or telemetry.

Supported data scale

One to a few hundred values each; bars create one rect per value.

Edge cases
  • Gaps split the line; isolated values are drawn as dots.
  • All values equal: a flat line mid-height.
  • Bars always include zero; negative bars hang below a baseline.
  • Values outside a fixed min/max are clamped.
Errors
Code Category Cause
SPARKLINE_OPTIONS configuration Missing label, non-numeric values, invalid variant or color, max <= min, invalid formatters.
CFG_INVALID_VALUE / CFG_UNKNOWN_OPTION configuration Invalid or unknown configuration.

A failed construction leaves the host untouched.

Known limitations
  • Not interactive; minimum and maximum are not marked visually.
  • Manual screen-reader verification is pending.
  • theme applies only the properties listed in section 5; tooltips, legends, annotations, point events, and synchronized crosshairs do not apply (static images).
Unsupported scenarios
  • Axes, labels, legends, tooltips.
  • Win/loss and bullet variants.