D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
rambler
Full window
Github gist
Homelessness by state in the USA
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Adding Tooltips</title> <script type="text/javascript" src="https://d3js.org/d3.v3.js"></script> <style type="text/css"> body { background-color: white; font-family: Arial; } svg { background-color: white; } rect { fill: rgb(60, 160, 180); } rect:hover { fill: rgb(30, 80, 100); } text { fill: black; } </style> </head> <body> <script type="text/javascript"> var row_height = 15; var chart_width = 800 var svg = d3.select("body") .append("svg") .attr("width", chart_width) .attr("height", 54*row_height); d3.csv("homeless_by_state_2014.csv", function(data) { data.sort(function(a, b) { return d3.descending(+a.year_2014, +b.year_2014); }); var rects = svg.selectAll("rect") .data(data) .enter() .append("rect"); rects.attr("x", 20) .attr("y", function(d, i) { return i * row_height; }) .attr("width", function(d) { return d.year_2014 * chart_width/120000; }) .attr("height", row_height-2) .append("title") .text(function(d) { return d.state + "'s 2014 homeless population was " + d.year_2014; }); var labels = svg.selectAll("text") .data(data) .enter() .append("text"); labels.attr("x", 0) .attr("y", function(d, i) { return i*row_height+10; }) .attr("font-size", 9) .text(function(d) { return d.state; }); }); </script> </body> </html>
Modified
http://d3js.org/d3.v3.js
to a secure url
https://d3js.org/d3.v3.js