StealThis .dev

Area Chart

A smooth area chart with gradient fill under the curve, multi-series stacking, animated draw-in, and interactive crosshair tooltip. Built with vanilla JS and SVG.

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

Code

Features

  • Gradient fill — SVG <linearGradient> from accent color to transparent
  • Multi-series — stacked or overlapping area layers
  • Crosshair tooltip — vertical line snaps to nearest data point
  • Smooth bezier — cubic bezier interpolation for organic curves
  • Animated path — draw-in animation on mount
  • Responsive — ResizeObserver-driven redraw

How it works

  1. Each series produces a closed SVG polygon path (back along the baseline)
  2. A <defs> gradient is defined per series and referenced by fill
  3. Mouse move events find the nearest X-index and render a crosshair + tooltip