Sparkline
A small inline line or bar chart, drawn as SVG from a comma-separated string of numbers.
<arc-sparkline>Overview
Sparkline is a small trend chart, 120 by 32 pixels by default. Put it in a table cell next to a metric, beside a stat card, or in a dashboard grid. It has no axes, labels or tooltips. For those, use a full chart.
Pass the values as a comma-separated string in data. type="line" draws a line with rounded joins, and fill adds a shaded area under it. type="bar" draws evenly spaced bars that fill in more strongly on hover. The line draws itself in over 800ms when it first renders, and appears at once under prefers-reduced-motion.
The color is --accent-primary by default. color takes any CSS color, such as var(--color-success) for revenue or #dc2626 for an error rate, and an "r, g, b" triplet still works. It sets the line, the area under it at 10% opacity, and the bars at 30% (60% on hover).
Guidelines
Do
- Keep data short, 5 to 20 points. Past about 30 the chart becomes an unreadable blob
- Use a line for continuous trends like revenue over time or request latency
- Use bars for discrete counts like daily totals or categories
- Set `fill` to stress how large a trend is, not only its direction
Don't
- Don't base important decisions on a sparkline alone. It has no axes, labels or precision
- Don't put dozens of line sparklines in one table. Each one draws itself in, and there's no setting to turn that off
Features
- A baseline rule in `--border-subtle`
- CSS parts `svg`, `line`, `area` and `bar`
- `display: inline-block` with `vertical-align: middle`, so it lines up with surrounding text
- The SVG is `aria-hidden`, so screen readers skip it. Put the number it illustrates in visible text
Preview
Usage
<script type="module" src="@arclux/arc-ui"></script>
<!-- Line sparkline -->
<arc-sparkline data="10,25,18,30,22,35,28,40,32" type="line"></arc-sparkline>
<!-- Line with area fill -->
<arc-sparkline data="10,25,18,30,22,35,28,40,32" type="line" fill></arc-sparkline>
<!-- Bar sparkline -->
<arc-sparkline data="10,25,18,30,22,35,28,40,32" type="bar"></arc-sparkline>
<!-- Custom size and color -->
<arc-sparkline
data="5,12,8,20,15,25,18"
type="line"
width="200"
height="48"
color="var(--color-success)"
></arc-sparkline>import { Sparkline } from '@arclux/arc-ui-react';
export function MetricCard() {
return (
<div style={{ display: 'flex', alignItems: 'center', gap: 16 }}>
<span style={{ fontSize: 24, fontWeight: 600 }}>2,847</span>
<Sparkline data="10,25,18,30,22,35,28,40,32" type="line" fill />
</div>
);
}<script setup>
import { Sparkline } from '@arclux/arc-ui-vue';
</script>
<template>
<div style="display: flex; align-items: center; gap: 16px;">
<span style="font-size: 24px; font-weight: 600;">2,847</span>
<Sparkline data="10,25,18,30,22,35,28,40,32" type="line" fill />
</div>
</template><script>
import { Sparkline } from '@arclux/arc-ui-svelte';
</script>
<div style="display: flex; align-items: center; gap: 16px;">
<span style="font-size: 24px; font-weight: 600;">2,847</span>
<Sparkline data="10,25,18,30,22,35,28,40,32" type="line" fill />
</div>import { Component } from '@angular/core';
import { Sparkline } from '@arclux/arc-ui-angular';
@Component({
imports: [Sparkline],
template: `
<div style="display: flex; align-items: center; gap: 16px;">
<span style="font-size: 24px; font-weight: 600;">2,847</span>
<arc-sparkline data="10,25,18,30,22,35,28,40,32" type="line" fill />
</div>
`,
})
export class MetricCardComponent {}import { Sparkline } from '@arclux/arc-ui-solid';
export function MetricCard() {
return (
<div style={{ display: 'flex', 'align-items': 'center', gap: '16px' }}>
<span style={{ 'font-size': '24px', 'font-weight': '600' }}>2,847</span>
<Sparkline data="10,25,18,30,22,35,28,40,32" type="line" fill />
</div>
);
}import { Sparkline } from '@arclux/arc-ui-preact';
export function MetricCard() {
return (
<div style={{ display: 'flex', alignItems: 'center', gap: 16 }}>
<span style={{ fontSize: 24, fontWeight: 600 }}>2,847</span>
<Sparkline data="10,25,18,30,22,35,28,40,32" type="line" fill />
</div>
);
}API
datastring''- Comma-separated numeric values that define the chart data points (e.g. "10,25,18,30,22,35,28"). Parsed into a number array at render time. Non-numeric entries are silently dropped.
colorstring''- Color for the line, the area under it and the bars. Takes any CSS color (
#16a34a,green,var(--color-success)) or an"r, g, b"triplet. The area fill is the color at 10% opacity and bars at 30% (60% on hover). Defaults tovar(--accent-primary)when not set. type'line' | 'bar''line'- Chart type. Line renders a polyline with optional area fill; bar renders evenly spaced rectangles.
widthnumber120- SVG viewport width in pixels.
heightnumber32- SVG viewport height in pixels.
fillbooleanfalse- When true and type is "line", fills the area beneath the curve with
colorat 10% opacity.