Ir al contenido
Español

Cómo funciona

An inline SVG drawn at its exact pixel size, so the dot stays round and the stroke stays crisp. The curve is a monotone cubic: it passes through every point and never bulges past a peak or a dip, which a plain smoothing would. The line draws in with stroke-dashoffset on a normalised path length, the area fades in after it, and the last-value dot appears with a halo that swells once and settles. Pointing anywhere over it moves the dot to the nearest point on a spring and reports it through onActiveChange, so a table cell can show that day's value next to it.

Úsalo para

  • Trends beside a number in a table, a list or a KPI card, where shape matters more than exact values.

Busca otra opción cuando

  • When people need axes, units or comparisons between series: use a line chart.

Uso

import { Sparkline } from './Sparkline.jsx'

export function VisitorsCell({ history }) {
  return (
    <Sparkline
      data={history}
      width={96}
      height={28}
      variant="area"
      tone={1}
      label={`Visitors from ${history[0]} to ${history.at(-1)} over 14 days`}
      formatValue={(n) => n.toLocaleString('en-US')}
    />
  )
}

Propiedades

PropiedadTipoPor defectoQué hace
datanumber[] | { value: number }[]—Values in time order. Non-numbers are skipped.
width / heightnumber96 / 28Size in px; the chart draws at exactly this size so dots stay round.
variant'line' | 'area''line'A line alone, or with a gradient fill that fades out at the bottom.
tone / color1-8 / string1--ds-chart-N, or any colour.
smoothbooleantrueA monotone curve that passes through every point without overshooting; false draws straight segments.
dot / baselineboolean / numbertrue / -The last-value dot, and an optional dashed reference line at a value.
tooltip / formatValue / onActiveChangeboolean / (v) => string / (index, value) => voidtrueA value tag while pointing; or turn it off and show the value yourself with onActiveChange.
labelstring—Accessible name. By default it states the first, last, lowest and highest values.

Accesibilidad

  • The chart is one image with a text summary (first, last, low and high by default); pass label for a sentence in your own words.
  • The SVG itself is hidden from assistive technology; the value tag is decorative.
  • Keep the number next to it in text, as the demo does: the chart is a supplement, not the only carrier of the value.
  • Reduced motion removes the draw, the halo pulse and the dot slide.

Movimiento

Line: 900ms draw on the reveal curve. Area: 700ms fade from 300ms. Dot: appears at 760ms; halo swells and settles over 1200ms. Pointing: 260ms spring slide.

Añádelo a tu proyecto

Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.

Sparkline.jsxsparkline.csstokens.cssREADME.md

Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

Gráficos
Trilateración viene con Pro. La vista previa aparece al desbloquearlo.