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.

Server safePure SVG0 dependenciesSource

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.

Signups trend
Signups trend
IndexValue
012
119
214
327
424
531
638
<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

Signups over 7 days
Signups over 7 days
IndexValue
012
119
214
327
424
531
638
<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

A chart is not an image

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.

Props for Sparkline
PropTypeDefaultDescription
datareadonly number[]The trend. Non-finite entries are dropped before anything is drawn.
heightnumberHeight of the internal coordinate space, in px. Default `32`.
widthnumberWidth of the internal coordinate space. The sparkline stretches to fill its container, so this only sets the aspect ratio the geometry is designed against.
strokestringAny CSS colour. Defaults to the `--vk-chart-1` token.
fillboolean | stringFill under the line: `true` for a tint of `stroke`, or an explicit CSS colour.
strokeWidthnumber
showLastPointbooleanDot on the final value - the "where are we now" cue.
curve'linear' | 'smooth'
titlestring
descriptionstring
accessibleTablebooleanVisually hidden `<table>` of the values. On by default.
formatValue(value: number) => string
xLabelstring
yLabelstring

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.