D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
thomasgpadilla
Full window
Github gist
NHPRC Grants, Sorted by Amount
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>NHPRC Horizontal Bar Chart</title> <script type="text/javascript" src="https://d3js.org/d3.v3.js"></script> <style type="text/css"> svg { background-color: #ECF0F1; } rects { background-color: black; } </style> </head> <body> <svg width="1000"> 2 <rect x="0" y="0" width="1000" height="150" fill="SpringGreen" /> <text x="10" y="80" fill="charcoal" font-size="36" font-weight="bold" font-family="Andale Mono">NHPRC Grants</text> <text x="10" y="105" fill="charcoal" font-size="14" font-weight="bold" font-family="Andale Mono">Sorted by Amount Awarded</text> <text x="10" y="125" fill="charcoal" font-size="10" font-weight="bold" font-family="Andale Mono">Source: Data.gov</text> <script type="text/javascript"> var svg = d3.select("body") .append("svg") .attr("width", 1000) .attr("height", 5000); d3.csv("nhprc.csv", function(data) { data.sort(function(a, b) { return d3.descending(+a.FinalGrantAward, +b.FinalGrantAward); }); var rects = svg.selectAll("rect") .data(data) .enter() .append("rect"); rects.attr("x", 0) .attr("y", function(d, i) { return i * 10; }) .attr("width", function(d) { return d.FinalGrantAward / 3000; }) .attr("height", 8) .append("title") .text(function(d) { return d.YearAwarded + ": " + d.Institution + " was awarded $" + d.FinalGrantAward; }); }); </script> </body> </html>
Modified
http://d3js.org/d3.v3.js
to a secure url
https://d3js.org/d3.v3.js