Skip to content
InsightCharts

Search

Search guides and components

Sparkline

A word-sized line or bar series without axes, with the latest point marked.

Use when
Showing the recent history of a number inside a stat tile, a table cell or a sentence, where the shape of the trend matters and exact values do not.
Avoid when
Anything the reader must read values from or compare across series (use line chart); fewer than about 5 points (state the change in words or use big number with a delta).

Preview

Composition

Used in

5 molecules and 2 templates use sparkline.

Molecules

5

A vertical sequence of dated events along a rail, each with a short explanation and, optionally, a small chart or figure.

Two states of one measure side by side, as figures or small charts, with the change between them stated in the middle.

A table whose rows carry inline sparklines, deltas and in-cell bars beside their exact values, from rows and a column config.

A pull-quote paired with the statistic or small chart that backs it up, side by side and stacking in narrow containers.

A KPI card computed from a series: the latest value, its change against a baseline in the same data, and a sparkline of the series.

Templates

2

A recurring report. It has a masthead with the report name and period, a headline that states the main change, a KPI grid with changes and sparklines, a ranked list beside one or two trend charts, an optional comparison table, short notes and a source note.

A story told in date order. It has a headline, one overview exhibit of the whole period (a timeline chart or an annotated line), dated chapters along a rail, a closing paragraph and a source note. Each chapter has a short text and an optional small exhibit.

Installation

$ pnpm dlx shadcn@latest add @insightcharts/sparkline

The CLI copies the source into your project and needs the @insightcharts registry in components.json; see installation. With the package, import it by name:

import { Sparkline } from "insightcharts";

Examples

With a reference band

Blood glucose over 48 readings

Blood glucose, mmol/L. The band is the 3.9 to 7.0 target range.

Illustrative data

Bars: gains and losses

Area fill, full width

Stress: 400 points in 160px

Props

PropTypeDefaultDescription
yrequiredstringValue field.
xstringTime or label field, used in the tooltip and alt text. Rows are drawn in data order.
mark"line" | "bar""line"Line for a trend, bars for discrete counts or gains and losses (negative bars take the negative colour).
extremesbooleanfalseMark the lowest and highest points with small dots.
band[number, number]Shaded reference range in value units, e.g. a normal range.
areabooleanfalseLight fill under the line; forces a zero baseline.
showValuebooleanfalsePrint the last value after the line.
zerobooleanInclude zero in the scale. Default: off for lines, always on for bars.
Common chart props 29

Every chart built with defineChart accepts these on top of its own props.

PropTypeDescription
dataDataInputRows, CSV text, a URL, { url, path }, an async function, or an Arrow-style table. Omit inside <InsightData>.
transformTransform | Transform[]A pipeline of transforms applied before drawing.
titlestringThe title. One plain statement of what the data shows, with the number and the period ("Monthly churn fell from 4.2% to 2.1% in 2024"), or a plain label ("Monthly churn, 2024"). One clause, no figures of speech.
subtitlestringMeasure, unit, population, period.
sourcestringData source, shown as "Source: ...".
notestringMethod notes or caveats.
heightnumber | stringCSS height of the plot. Default 360.
aspectnumberWidth / height. Overrides height.
highlightstring | string[]The entity (or entities) the title is about. Every other series is drawn in grey.
annotationsAnnotation[]Reference lines, shaded bands and callouts, in data coordinates.
formatFormatSpecHow to print values: "compact", "percent", "currency:USD", "{value} kg", Intl options, or a function.
legendbooleanShow the legend. Default: shown when there are two or more series.
selectboolean | stringMake marks clickable to filter. Inside <InsightData> the selection filters every other chart. Pass a field name, or true to use the chart's category field.
onSelect(values: string[], field: string) => voidCalled with the selected values whenever the selection changes.
optionEChartsOption | ((option: EChartsOption, ctx: BuildContext) => EChartsOption)Deep-merged over the generated ECharts option, or a function that receives and returns it. Use it for ECharts settings no prop covers.
themeThemeInputA theme, or a partial set of tokens merged over the surrounding theme, for this chart only.
modeModeInput"auto" (default) follows the page, "system" follows the OS, or force "light" / "dark".
rendererRendererInput"auto" (default) uses SVG for light charts and canvas for heavy ones.
animatebooleanSet false to disable animation. Reduced-motion preferences are always respected.
lazybooleanMount the chart only when it scrolls near the viewport. Default true.
groupstringLink tooltips with other charts sharing this group id.
exportableboolean | ExportFormat[]Show an export menu: true or a list of formats from png, jpeg, svg, pdf, csv, json.
tablebooleanShow a collapsible "View data" table under the chart.
altstringAccessible description: the chart type and measures, then the main pattern and the notable values.
idstringStable id for this chart's selection in the shared store.
onEventsRecord<string, ChartEventHandler>ECharts event handlers, e.g. { click: (params, chart) => {} }. Prefix a name with zr: to bind to the canvas itself.
onReady(chart: EChartsInstance) => voidCalled with the ECharts instance once it is created.
classNamestringClass name for the outer <figure>.
styleCSSPropertiesInline style for the outer <figure>.