Sparkline
The <velin-sparkline> Web Component renders a tiny inline-SVG trend chart from a CSV value array, animates the stroke draw-in, and exposes a live update() API for tick-driven dashboards.
Basic
<velin-sparkline
values="3,5,4,7,6,8,7,11,9,12"
area glow
animate="draw"
label="Weekly users"></velin-sparkline>
Attributes
| Attribute | Type | Notes |
|---|---|---|
values | CSV / JSON array | Required; numeric data points |
width / height | number | SVG viewBox; defaults 320 × 96 |
min / max | number | Clamp range; default derived from values |
area | boolean | Adds gradient area fill below the line |
glow | boolean | Loops velin-sparkline-glow on the SVG |
animate | draw | none | Default draw — once on connect |
label | string | Sets role="img" + aria-label |
JavaScript API
const spark = document.querySelector('velin-sparkline');
spark.update([3, 5, 4, 7, 9, 12, 14]); // morphs path + triggers value-bump
spark.values; // current values getter
spark.values = [1, 2, 3]; // setter (reflects to attribute)
Live tick
setInterval(() => {
const last = spark.values.at(-1);
const next = last + (Math.random() - 0.5) * 4;
spark.update([...spark.values.slice(1), next]);
}, 4000);
Accessibility
- Provide a
labelattribute so screen readers announce the chart purpose. - Under
prefers-reduced-motion: reducethe draw-in is skipped and the path is shown fully drawn. - For data tables behind the chart, use a visually-hidden
<table>sibling for full data exploration.