StealThis .dev

Sparkline

A compact inline SVG sparkline chart for embedding in tables, cards, or dashboards. Supports line and bar variants, trend coloring (up/green, down/red), and an optional last-value dot.

Open in Lab
svg react tailwind vue svelte
Targets: TS JS HTML React Vue Svelte

Code

Features

  • Line & bar modes — switch between polyline and rect-bar rendering
  • Trend color — automatically green if trending up, red if down
  • Last-value dot — optional highlighted endpoint with tooltip
  • Inline — fits inside table cells or card headers
  • Zero baseline — bars always start from bottom; lines trace the data

How it works

  1. Min/max values normalize data points to the SVG viewport height
  2. A <polyline> traces all normalized points for the line variant
  3. Bar variant renders <rect> elements with height proportional to value
  4. The last point gets a <circle> marker for the “current value” indicator