D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
trinary
Full window
Github gist
basic bars, oriented correctly
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.7.4/d3.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } svg { width:100%; height: 100% } </style> </head> <body> <svg></svg> <script> var d = [ {value: 7}, {value: 20}, {value: 33}, {value: 9 }, {value: 22 }, {value: 44}, {value: 15}, {value: 26} ]; var svg = d3.select("svg"); // We've taken the scaling factor out into its own function var yScale = function(d) { return d * 5; } var bars = svg.selectAll(".bars") .data(d); bars.enter() .append("rect") .classed("bars",true) .attr("x", function(d,i) { return 20 + (i * 40)}) .attr("y", function(d,i) { return 300 - yScale(d.value);}) .attr("width", 29) .attr("height", function(d,i) { return yScale(d.value);}) .style("fill","grey"); </script> </body>
https://cdnjs.cloudflare.com/ajax/libs/d3/4.7.4/d3.min.js