Charts
Sparkline
A tiny, axis-free trend line meant to sit inside a sentence, a table cell or a stat card. Pure SVG, no measurement, no dependencies.
Import
Charts live at their own subpath with their own stylesheet, so an app that never draws one pays nothing for them.
import { Sparkline } from '@the_viveksingh/vivek-ui/charts'
import '@the_viveksingh/vivek-ui/charts.css'Inline trend
No axes, no legend. Sized to sit beside a number in a stat tile.
| Index | Value |
|---|---|
| 0 | 12 |
| 1 | 19 |
| 2 | 14 |
| 3 | 27 |
| 4 | 24 |
| 5 | 31 |
| 6 | 38 |
<Sparkline data={[12, 19, 14, 27, 24, 31, 38]} title="Signups trend" />In a stat tile
The pattern it exists for: a KPI with its recent shape next to it.
Signups
1,284
| Index | Value |
|---|---|
| 0 | 12 |
| 1 | 19 |
| 2 | 14 |
| 3 | 27 |
| 4 | 24 |
| 5 | 31 |
| 6 | 38 |
<Card padding="lg">
<Card.Body>
<Text size="sm" tone="muted">Signups</Text>
<Heading level={3} size="2xl">1,284</Heading>
<Sparkline
data={[12, 19, 14, 27, 24, 31, 38]}
fill
showLastPoint
title="Signups over 7 days"
/>
</Card.Body>
</Card>Accessibility
Every chart carries role="img" with a generated accessible name, and renders a real <table> alongside it — visually hidden, never display: none — so a screen-reader user gets the actual numbers instead of "chart". Set accessibleTable={false} only if you have provided the data in a table elsewhere on the page.
No series is ever encoded by colour alone: each carries a distinct dash pattern and marker shape on top of its colour, so the chart survives greyscale printing and every common form of colour blindness.
The palette is verified rather than asserted. Each theme has its own six colours, because one set cannot clear the 3:1 non-text contrast threshold against both a white and a near-black plot surface. Separation is measured under simulated protanopia, deuteranopia and tritanopia: for one to four series — which is nearly every chart — the closest pair sits at ΔE 17, slightly better than the unmodified Okabe-Ito palette it is derived from. Past four series the dash patterns and marker shapes carry the distinction.
Hostile data
Real series contain gaps and rubbish. Every chart is tested against empty arrays, a single point, all-equal values, negatives crossing zero, NaN, ±Infinity, 1e308 and 1e-320, with an assertion that no rendered SVG attribute ever contains NaN. A bad row degrades the chart; it does not blank your page.
Props
Generated from the package's own type declarations, so this table cannot drift from the code.
| Prop | Type | Default | Description |
|---|---|---|---|
data | readonly number[] | — | The trend. Non-finite entries are dropped before anything is drawn. |
height | number | — | Height of the internal coordinate space, in px. Default `32`. |
width | number | — | Width of the internal coordinate space. The sparkline stretches to fill its container, so this only sets the aspect ratio the geometry is designed against. |
stroke | string | — | Any CSS colour. Defaults to the `--vk-chart-1` token. |
fill | boolean | string | — | Fill under the line: `true` for a tint of `stroke`, or an explicit CSS colour. |
strokeWidth | number | — | — |
showLastPoint | boolean | — | Dot on the final value - the "where are we now" cue. |
curve | 'linear' | 'smooth' | — | — |
title | string | — | — |
description | string | — | — |
accessibleTable | boolean | — | Visually hidden `<table>` of the values. On by default. |
formatValue | (value: number) => string | — | — |
xLabel | string | — | — |
yLabel | string | — | — |
Every remaining prop is spread onto the root element, so all standard HTML and ARIA attributes work. className and style are merged with the library's own, never replaced, and the ref forwards to the root DOM node.