Skip to main content
196

Search Lumen

Find components, APIs, guides, and recipes.

GitHub
Web docs
Data display

Sparkline

Shows a compact, text-labelled trend beside an existing metric.

FrameworksAstro · React · Elements

Registry commandlumen add Sparkline

InteractionNative markup

← All chart guides · Framework setup · Native counterparts

01

See it and copy it

Framework example

Explore the live chart, then open its code for Astro, React, or Elements.

AstroCode target · live preview uses Astro
Weekly downloads
18,420
Illustrative week · 21–27 September 2026
Daily downloads rose from 1,820 on Monday to a weekly peak of 3,740 on Sunday3,740 downloads on the strongest day
View Sparkline code

Framework usage

Switch targets to compare the adapter code. This live preview runs the Astro example. React and Elements use their own behavior APIs; complete the matching framework setup before copying an example.
astro
---
import { Card, CardContent, Sparkline, Stat, StatDescription, StatLabel, StatTrend, StatValue } from '@santi020k/lumen-astro'

const values = [1820, 2160, 2480, 2240, 2860, 3120, 3740]
---

<Card style="width: 100%; max-width: 28rem">
  <CardContent>
    <Stat variant="bare">
      <StatLabel>Weekly downloads</StatLabel>
      <StatValue>18,420</StatValue>
      <StatDescription>Illustrative week · 21–27 September 2026</StatDescription>
      <Sparkline
        area
        label="Daily downloads rose from 1,820 on Monday to a weekly peak of 3,740 on Sunday"
        style="width: 100%; height: 4rem; margin-block: 1rem"
        {values}
      />
      <StatTrend tone="success">3,740 downloads on the strongest day</StatTrend>
    </Stat>
  </CardContent>
</Card>
Edit Sparkline in browser

When to use Sparkline

Use beside a Stat or a table metric when the overall direction matters more than individual coordinates.

  • The endpoint marks the latest available value. area adds a fill below the line; showEndpoint controls the final dot.
  • Keep the current value and units visible beside the sparkline. Its SVG is decorative; the labeled wrapper provides the accessible meaning.

Prepare the data

ts
const values: readonly number[] = [42, 48, 63, 58, 74, 91]
const label = 'Weekly downloads increased from 42 to 91'
  • Supply finite numbers in the order readers should follow. Values are spaced by their array index.
  • The required label is the textual explanation of the trend. Include its measure, period, and a useful observation.

Shared data and formatting guidance →

Avoid misleading comparisons

  • This compact chart has no axes, exact-data disclosure, or time-scale prop. Use LineChart when users need to compare individual values or irregular intervals.
  • Do not replace missing observations with zero to satisfy the number array. Choose a chart with an explicit nullable data contract when gaps matter.

Chart accessibility and keyboard guidance →

02

Choose your target

Add this component

Choose the package for your runtime. All adapters share the Lumen stylesheet. Use the matching registry command when you want a local wrapper for that framework.

bash@santi020k/lumen-astro
pnpm add @santi020k/lumen-astro
pnpm add @santi020k/lumen-astro
bashAstro wrapper
lumen add Sparkline
lumen add Sparkline

API reference

Lumen-specific props and runtime attributes for the Astro primitive. Use the framework differences above and the copyable examples for React composition and Elements attributes; the public adapter types define their supported contracts.

AttributeValuesDefaultDescription
valuesnumber[]requiredProvides ordered values for the compact trend.
labelstringrequiredCommunicates the trend in text because the SVG is intentionally decorative.
areabooleanfalseAdds a subtle tokenized fill below the line.
showEndpointbooleantrueMarks the latest value with a color-independent endpoint.
toneLumenChartTone"series-1"Selects a categorical or explicitly semantic chart tone.
class, classNamestring""Merges custom classes with the generated ui-* root classes.
...native attributesHTML attributes-Forwards standard attributes to the root element unless the component consumes them.

Web docsFull catalog