D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
fernandoremiro
Full window
Github gist
Module 3 - Exercise
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Module 3 - Exercise</title> <script type="text/javascript" src="https://d3js.org/d3.v3.js"></script> <style type="text/css"> body { background-color: white; } svg { background-color: white; } </style> </head> <body> <p> <b> Social expenditure in OECD countries (% of GDP) </b> </p> <script type="text/javascript"> var svg = d3.select("body") .append("svg") .attr("width", 600) .attr("height", 1000); d3.csv("OECD_social.csv", function(data) { data.sort(function(a, b) { return d3.descending(+a.Total, +b.Total); }); var rects = svg.selectAll("rect") .data(data) .enter() .append("rect"); rects.attr("x", 0) .attr("y", function(d, i) { return i * 16; }) .attr("width", function(d) { return d.Total * 11; }) .attr("height", 14) .attr("fill", "#2c7fb8") .append("title") .text(function(d) { return d.Country + "'s social expenditure represents " + d.Total + "% of GDP" }) var countries = svg.selectAll("text") .data(data) .enter() .append("text"); countries.attr("x", 0) .attr("y", function(d,i) { return i * 15.9 + 13; }) .attr("fill", "#FFFFFF") .attr("font-size", "12px") .attr("font-weight", "bold") .attr("font-family", "sans-serif") .text(function(d) { return d.Country}) }); </script> </body> </html>
Modified
http://d3js.org/d3.v3.js
to a secure url
https://d3js.org/d3.v3.js