D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
pcfields
Full window
Github gist
Animated Bar chart with D3.js
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } </style> </head> <body> <h1>Animated Bar chart with D3.js</h1> <div id="chart"> <div></div> <div></div> <div></div> <div></div> <div></div> </div> <script> const data = [ 90, 70, 50, 30, 10 ] d3.select('#chart') .selectAll('div') // pair each number in the array with an empty div .data(data) // color, height, and spacing via CSS .attr('class', 'bar') .style('width', function(d) { // use the data items as pixel widths return d + 'px' }) </script> </body>
https://d3js.org/d3.v4.min.js