StealThis .dev

Donut Chart — Product Categories

A donut chart showing product category distribution with icon header, colored segments, animated arcs, and a clean legend. Ideal for shipping, inventory, or sales dashboards.

Open in Lab
vanilla-js svg
Targets: JS HTML

Code

Features

  • Donut chart — five colored arc segments with a hollow center
  • Animated arcs — slices reveal with a staggered fade-in animation
  • Hover highlight — segment scales up on hover for emphasis
  • Icon header — pink/magenta accent line with an inline SVG package icon
  • Dynamic legend — color-coded labels and percentages built from data

How it works

  1. A DATA array defines five product categories with labels, values, and colors
  2. SVG <path> arcs are computed using polarToXY() and arcPath() helpers
  3. Each arc animates in with a staggered fadeIn keyframe
  4. On hover, the active slice gets transform: scale(1.06) via CSS
  5. The legend is generated dynamically, showing colored swatches and percentage values