Skip to documentation content

Sparkline

A word-sized trend chart for metric cards, tables, and dense dashboards.

Basic Sparkline

Overview

A sparkline shows the shape of a series without axes, gridlines, or labels, so it fits beside the number it explains: a metric card, a table row, or a list of services. Use it to answer "which way is this going and how bumpy was it?" at a glance. When readers need exact values, dates, or comparisons between series, use a Line Chart instead.

Anatomy

Sparkline owns the data, the plotted dataKey, its colors, and the value scale. Choose a variant of line, area, or bar. Optional parts add context without adding chrome: Dot marks the latest point or the extremes, ReferenceLine draws a dashed baseline at a value or a statistic such as the average, and Tooltip reveals one point at a time on hover.

Accessibility

The canvas carries a generated accessible name that states the trend direction, the first and last values, and the range, for example "Revenue sparkline, up from $31.2k to $48.2k". Pass ariaLabel when the surrounding text already says this, or when the sparkline needs more specific wording. Keep the headline number in real text next to the chart; the tooltip is pointer-operated and must not be the only way to read a value.

Installation

npm install honestui

Usage

import { Sparkline, type ChartConfig } from "honestui/charts";
<Sparkline
  data={data}
  config={chartConfig}
  dataKey="revenue"
  xDataKey="week"
  variant="area"
  className="h-12 w-28"
>
  <Sparkline.Dot points="last" />
  <Sparkline.Tooltip valueFormatter={(value) => `$${value}k`} />
</Sparkline>

Give the sparkline an explicit size. Its plot is inset only as far as the stroke and dots need, so the line reaches the edges of its box. The tooltip is attached to the page rather than the chart, so it can rise above a chart only a few pixels tall.

Examples

Variants

variant='line' | 'area' | 'bar'

Lines suit continuous measures, areas add weight to a volume, and bars suit discrete counts such as daily signups. Bars start from zero unless the data has negative values; lines scale to the data range so small movements stay visible.

Dots and reference lines

ReferenceLine and Dot

ReferenceLine accepts a number or one of average, first, min, or max. Dot marks the last point, the extremes, both, or all points, using the same dot variants as the Line Chart.

In a table

Sparklines in table rows

Each row passes its own config, so one data key can take a rising or falling color. A reference line at the first value shows where the period started.

Loading State

isLoading='true'

A loading sparkline draws a neutral placeholder shape. A loading pill would not fit a chart this small, so the state is announced to assistive technology only.

API Reference

Sparkline
PropTypeDefaultDescription
data*TData[]–

The ordered points to plot.

config*ChartConfig–

The label and theme colors for dataKey. Several colors draw a horizontal gradient.

dataKey*keyof TData & string–

The numeric value to plot. Empty or non-numeric values leave a gap.

xDataKeykeyof TData & string–

Labels each point in the tooltip, such as a date.

variantline|area|bar"line"

How the series is drawn.

curvelinear|smooth|step"linear"

The line interpolation. Ignored by bars.

strokeWidthnumber1

Line width in pixels.

minnumber–

Lower bound of the value scale. Lines default to the smallest value; bars to zero.

maxnumber–

Upper bound of the value scale. Defaults to the largest value.

connectNullsbooleanfalse

Draws the line across missing values instead of leaving a gap.

classNamestring–

Classes for the container. Give the chart an explicit width and height.

animationbooleantrue

Enables the intro animation. Reduced-motion preferences disable it.

isLoadingbooleanfalse

Draws a neutral placeholder and announces the loading state.

ariaLabelstring–

Accessible name for the chart. A trend summary is generated when omitted.

chartOptionsRecord<string, unknown>–

ECharts options merged over the generated option.

Dot
PropTypeDefaultDescription
pointslast|extremes|last-and-extremes|all"last"

Which points carry a dot. Ignored by bars.

variantdefault|border|colored-border|ping"border"

The dot style, shared with the Line Chart.

ReferenceLine
PropTypeDefaultDescription
ynumber | "average" | "first" | "min" | "max""average"

A fixed value, or a statistic computed from the data. Add several to draw several lines.

Tooltip
PropTypeDefaultDescription
variantdefault|frosted-glass"default"

The tooltip surface.

roundnesssm|md|lg|xl"lg"

The tooltip corner radius.

valueFormatter(value: number) => string–

Formats the value, and the values in the generated accessible name.

labelFormatter(label: string, index: number) => string–

Formats the xDataKey heading.