StealThis .dev

Bar Chart

A vertical and horizontal bar chart built with SVG. Features animated bars, value labels on hover, grouped/stacked modes, and a responsive layout that redraws on resize.

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

Code

Features

  • Vertical & horizontal — toggle orientation with a button
  • Animated bars — scale-in animation from zero on mount
  • Value labels — inline labels on top of each bar
  • Color palette — auto-assigned distinct colors per group
  • Responsive — ResizeObserver redraws on container resize
  • Hover highlight — individual bar highlight with tooltip

How it works

  1. Bar widths/heights are computed as a proportion of the max data value
  2. SVG <rect> elements are rendered for each data point
  3. transform: scaleY() animates from 0 to 1 on mount
  4. A floating tooltip shows the label and exact value on hover