D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
sporange
Full window
Github gist
Module 3 - Male healthy life expectancy
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Adding Tooltips</title> <script type="text/javascript" src="../d3.v3.js"></script> <style type="text/css"> body { background-color: #ddddff; } svg { background-color: white; } </style> </head> <body> <script type="text/javascript"> var svg = d3.select("body") .append("svg") .attr("width", 300) .attr("height", 300); d3.csv("PHOF_LE_data_EngRegion.csv", function(data) { data.sort(function(a, b) { return d3.descending(a.HealthyLE_Male_2010to12, b.HealthyLE_Male_2010to12); }); var rects = svg.selectAll("rect") .data(data) .enter() .append("rect") .attr("fill","#009999"); rects.attr("x", 0) .attr("y", function(d, i) { return i * 30; }) .attr("width", function(d) { return d.HealthyLE_Male_2010to12 * 4; }) .attr("height", 25) .append("title") .text(function(d) { return d.Region + "'s male healthy life expectancy in 2010-12 was " + d.HealthyLE_Male_2010to12 + " years."; }); }); </script> </body> </html>