Display
Sparkline
A trend at a glance: a thin line, and a faint area under it, that fills the width it's given. Put it under a number in a card or at the end of a table row; for a chart people read closely, use Chart.
Installation
npx sinaui add sparklineCopy src/lib/ui/Sparkline.svelte and tokens.css. No dependencies.
Examples
Under a number
Each reading room's week of visits. The line takes the chart color; one value or none draws a flat hairline.
- Baghdad 400
- Córdoba 221
- Fez 102
<script lang="ts">
import Sparkline from '#lib/ui/Sparkline.svelte';
const rooms = [
{ name: 'Baghdad', visits: [42, 48, 45, 60, 58, 71, 76] },
{ name: 'Córdoba', visits: [30, 28, 33, 31, 29, 34, 36] },
{ name: 'Fez', visits: [18, 22, 16, 14, 12, 11, 9] }
];
const count = new Intl.NumberFormat('en-US');
</script>
<ul class="rooms">
{#each rooms as r (r.name)}
<li>
<span class="name">{r.name}</span>
<span class="num">{count.format(r.visits.reduce((a, b) => a + b, 0))}</span>
<Sparkline values={r.visits} label="{r.name} reading-room visits, last 7 days" />
</li>
{/each}
</ul>
<style>
.rooms {
display: grid;
gap: 1rem;
grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
margin: 0;
padding: 0;
list-style: none;
}
li {
display: grid;
gap: 0.25rem;
}
.name {
color: var(--ui-muted);
font-size: 0.8125rem;
}
.num {
font-size: 1.25rem;
font-weight: 500;
font-variant-numeric: tabular-nums;
}
</style>Props
| Prop | Type | Default |
|---|---|---|
values | number[] (required), oldest first | |
label | string (required): what it shows | |
height | number, in px | 32 |
area | boolean: shade under the line | true |
Accessibility
- An image with your
labelas its name; say the trend in it (“rising”, “flat”), since the drawing itself isn't read. - Put the number it belongs to in text next to it: a sparkline adds the shape, never the only figure.