Skip to content

Sparkline

A 44px trend line with no axes, a dot on the current point, a hover value and the same tokens as TimeseriesChart.

3.1 kB gzipSource Registry JSON

Sparkline playground

Props

color

Installation

npx shadcn@latest add https://sproutboat.com/ikada/r/sparkline.json

The CLI writes components/ikada/sparkline.tsx and merges the ikada theme into your CSS. Or take it from the package: import { Sparkline } from "@sproutboat/ikada/charts";

Usage

import { Sparkline } from "@/components/ikada/sparkline";

const requests = [12, 18, 15, 22, 28, 24, 31, 27, 35, 40, 36, 44];

<Sparkline
  ariaLabel="Requests, last 24 hours"
  data={requests}
/>

Examples

Default

A trend with no axes and a dot on now. Hover for the value of the nearest point; formatPoint adds its time as a title.

Colour

Any chart colour token. The same tokens colour TimeseriesChart.

Line only

Drop the fill and the current-point dot for the quietest form.

Fixed domain and height

Pin the domain so several sparklines compare on one scale.

Props

SparklineProps
PropTypeDescription
datarequiredreadonly number[]Values in time order, oldest first.
color"grid" | "other" | "requests" | "errors" | "deploy" | "2xx" | "3xx" | "4xx" | "5xx" | "series"Chart colour token for the line. Default `requests`.
heightnumberHeight in pixels. Default 44; the width fills the container.
areabooleanFill under the line. Defaults to true.
domainreadonly [number, number][min, max]. Defaults to the data's own range with a little air above and below, so a quiet series still shows its shape; pass [0, max] to compare several on one honest scale.
labelstringWhat the number is, shown once next to the value in the hover tooltip ("Requests 10,303"), so `formatValue` should not repeat it. Defaults to the first words of `ariaLabel` ("Requests" from "Requests, last 24 hours").
formatValue((value: number) => string)Formats the hover value. Default `(value: number): string => formatNumber(value)`.
formatPoint((index: number) => string)Title for a hovered point, usually its time ("14:00"). Without it the card shows just the row ("Requests 11"): a position like "Point 3" says nothing.
currentbooleanA dot on the newest value, so the eye lands on "now". Defaults to true.
classNamestringClasses merged onto the root element, after ikada's own.
aria-labelstring—
ariaLabelstring—

Source: src/charts/sparkline.tsx