D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
peripherie
Full window
Github gist
G7 GDP per capita in 2019 (module3)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>module3 D3 project</title> <script type="text/javascript" src="https://d3js.org/d3.v3.js"></script> <style> rect:hover{ fill-opacity: 0.8; stroke:#0000FF; } </style> <style type="text/css"> body { background-color: skyblue; } p { font-family: Helvetica; font-size: 36px; font-weight: bold; } </style> </head> <body> <script type="text/javascript"> d3.select("body") .append("p") .text("G7 GDP per capita in 2019 (US$)") ; var svg = d3.select("body") .append("svg") .attr("width", 1000) .attr("height", 300); d3.csv("d3G7GDP.csv", function(data) { data.sort(function(a, b) { return d3.descending(a["2019"], b["2019"]); }); var rects = svg.selectAll("rect") .data(data) .enter() .append("rect"); rects.attr("x", 0) .attr("y", function(d, i) { return i * 30; }) .attr("width", function(d) { return d["2019"] /100; }) .attr("height", 20) .attr("fill", "rgb(260, 30, 30)") .append("title") .text(function(d) { return d.country + "'s GDP per capita in 2019 is " + d["2019"] + "US$"; }); }); </script> </body> </html>
Modified
http://d3js.org/d3.v3.js
to a secure url
https://d3js.org/d3.v3.js