Skip to content

Sparkline

The shape of a number over time, small enough to sit beside the number. The last point carries the light.

import { Sparkline } from '@sypnia/ui/react'

On this page
  1. Beside a number
  2. Skeleton
  3. When to use it
  4. For everyone
  5. Props

Beside a number

Requests today18,240
Errors today31
Response time38ms
Code
import { Sparkline, Stat, StatGroup } from '@sypnia/ui/react';

export default function InAStat() {
  return (
    <StatGroup>
      <Stat label="Requests today" value="18,240" delta={<Sparkline label="Requests, last 12 hours: rising" data={[4, 6, 5, 8, 7, 9, 12, 11, 14, 13, 17, 19]} />} />
      <Stat label="Errors today" value="31" delta={<Sparkline label="Errors, last 12 hours: one spike, then falling" data={[2, 1, 2, 3, 2, 9, 4, 3, 2, 2, 1, 1]} />} />
      <Stat label="Response time" value="38" unit="ms" delta={<Sparkline label="Response time, last 12 hours: steady" data={[36, 39, 37, 38, 40, 38, 37, 39, 38, 36, 38, 38]} />} />
    </StatGroup>
  );
}

Skeleton

The real piece and its skeleton: the same box, so nothing moves when the data arrives.

Code
import { Sparkline, SparklineSkeleton } from '@sypnia/ui/react';

// The same box, flat, until the numbers arrive.
export default function Skeleton() {
  return (
    <div className="sy-row">
      <Sparkline label="Requests, last 12 hours" data={[4, 6, 5, 8, 7, 9, 12, 10, 11, 14, 13, 16]} />
      <SparklineSkeleton />
    </div>
  );
}

When to use it

Use it when

  • A number is shown and its recent direction matters: beside a Stat, in a table cell.

Do not use it when

  • The person needs to read values: it has no axes and no tooltip. Use a LineChart.
  • It would be the only sign of a problem: say it in words too.

For everyone

  • It is an image with a name: write the label as the conclusion («Errors: one spike, then falling»), not as «chart».

Props

SparklineTypeDefault
datarequired number[]
labelrequired string
height number 28
width number 96
  1. Beside a number
  2. Skeleton
  3. When to use it
  4. For everyone
  5. Props

    Search pages, sections and terms