Sparkline
Compact inline chart for embedding trend data inside cards, tables, and stat displays.
Import
import Sparkline from '$lib/components/Sparkline.svelte';Usage
<script lang="ts">
const data = [42, 55, 48, 72, 61, 85, 78, 93, 88, 104];
</script>
<Sparkline {data} />In Stats Cards
Combine sparklines with metric values for compact KPI cards.
Revenue $12,450 +18.2%
Active Users 2,150 +12.5%
Bounce Rate 42% -8.1%
Avg Session 4.8 min +9.4%
<div class="stat-card">
<div class="stat-info">
<span class="stat-label">Revenue</span>
<span class="stat-value">$12,450</span>
<span class="stat-delta positive">+18.2%</span>
</div>
<Sparkline data={revenueData} width={80} height={36} area />
</div>With Min / Max & Value
Enable minmax and value to annotate the chart with data extremes and the latest reading.
104
215
<Sparkline data={data} minmax value />Custom Colors
Use the color prop to set any stroke / fill color.
<Sparkline data={data} color="#22c55e" area />
<Sparkline data={data} color="#f43f5e" area />
<Sparkline data={data} color="#a855f7" area />API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
data | number[] | — | Array of numeric values to plot. |
width | number | 80 | SVG width in pixels. |
height | number | 32 | SVG height in pixels. |
color | string | — | Stroke and fill color. Defaults to the accent CSS variable. |
area | boolean | true | Fill the area beneath the line with a gradient. |
value | boolean | false | Show the last data value as text next to the chart. |
minmax | boolean | false | Annotate the minimum and maximum data points. |
class | string | — | Extra CSS classes applied to the root element. |