Line chart that draws on scroll

Animated charts usually mean pulling in a charting library, or hand-rolling a requestAnimationFrame loop that fights the scroll position. Neither is necessary when the chart is already an SVG path. This example sequences two draws — the axes settle first, then two years of revenue trace across them, last year's in grey and this year's in the accent, staggered so the eye reads them in order.

02selector · stagger · onProgress

The code

A full marketing site for a fictional subscription-analytics product. The dashboard's MRR lines plot themselves as it scrolls in, with the fill and the December tooltip following the draw; cohort curves fan out, a forecast draws past today with its confidence band widening, and three sparklines draw together.

Hero.tsx17 lines
const card = useRef<HTMLDivElement>(null);

<ScrollDraw
  selector=".line" stagger={0.18} easing="ease-out" once
  trigger={{ start: 'top 90%', end: 'top 30%' }}
  onProgress={(p) => card.current?.style.setProperty('--p', String(p))}
>
  <svg viewBox="0 0 760 240" preserveAspectRatio="none" className="mrr">
    <path className="grid" d="M6 155 H754 M6 120 H754 M6 85 H754" />
    <path className="area" d={smooth(thisYear) + ' L754 226 L6 226 Z'} />
    <path className="line prev" d={smooth(lastYear)} />
    <path className="line now"  d={smooth(thisYear)} />
  </svg>
</ScrollDraw>

/* .area    { opacity: calc((var(--p) - .6) * 2.5) }
   .tooltip { opacity: calc((var(--p) - .93) * 14) } */
Ledgerline, revenue analytics for subscription businesses: the first screen of its demo site

Revenue analytics for subscription businesses

Ledgerline

Live site

Related examples

Make your own in the SVG path viewer: set it up, watch it run, copy the code.

MIT licensed, zero runtime dependencies. Every API is a separate entry point, so you only ship what you import. Full API reference →