StealThis .dev

Line Chart

A fully responsive SVG line chart with animated paths, multi-series support, smooth bezier curves, grid lines, axis labels, and interactive tooltips. Built with vanilla JS and inline SVG — no dependencies.

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

Code

Features

  • Multi-series — render multiple data lines with distinct colors
  • Smooth bezier curves — cubic bezier interpolation for a polished look
  • Animated path draw — stroke-dasharray animation on mount
  • Interactive tooltip — follows mouse with formatted values and date labels
  • Grid lines & axis labels — responsive X/Y grid with configurable tick count
  • Responsive — redraws on window resize via ResizeObserver

How it works

  1. Data arrays are normalized to SVG viewport coordinates
  2. cubicBezierPath() builds the smooth path d attribute
  3. Hover events use getBoundingClientRect() to position a floating tooltip
  4. The chart redraws automatically when the container resizes