StealThis .dev

Scatter Plot

An interactive scatter plot with hover labels, optional bubble sizing, color-coded groups, animated point entrance, zoom-to-region, and regression line overlay.

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

Code

Features

  • Bubble sizing — optional third dimension mapped to circle radius
  • Color groups — data points auto-colored by group key
  • Hover tooltip — label, X, Y, and group shown in floating panel
  • Regression line — optional linear regression trend overlay
  • Animated entrance — points scale in from 0 on mount
  • Legend — color-coded legend per group

How it works

  1. X and Y domains are derived from Math.min/max across all data points
  2. Each point is an SVG <circle> positioned via normalized coordinates
  3. Tooltip follows cursor with mousemove + getBoundingClientRect()
  4. Optional regression line uses least-squares slope/intercept calculation