D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
manjumaj
Full window
Github gist
Bar Graph in Descending Order
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Baltimore Crime Index</title> <script type="text/javascript" src="https://d3js.org/d3.v3.js"></script> <style type="text/css"> svg { background-color: Light Blue; } rect { fill: Red; } </style> </head> <body> <h1>Baltimore Crime Index</h1> <h4><i>Hover over a bar for DomesticViolence Data</i></h4> <script type="text/javascript"> var svg = d3.select("body") .append("svg") .attr("width", 1200) .attr("height", 1500); d3.csv("Baltimore_Crime_Safety_2010.csv", function(data) { data.sort(function(a, b) { return d3.descending(a.DomesticViolence, b.DomesticViolence); }); var rects = svg.selectAll("rect") .data(data) .enter() .append("rect"); rects.attr("x", 10) .attr("y", function(d, i) { return i * 20; }) .attr("width", function(d) { return d.DomesticViolence * 10; }) .attr("height", 15) .append("title") .text(function(d) { return d.CSA2010 + "'s DomesticViolence score is " + d.DomesticViolence + "%"; }); }); </script> </body> </html>
Modified
http://d3js.org/d3.v3.js
to a secure url
https://d3js.org/d3.v3.js