D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
Lampadaire
Full window
Github gist
Weapons export worldwide_step2
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Data on weapons export in the world</title> <script type="text/javascript" src="https://d3js.org/d3.v3.js"></script> <style type="text/css"> h1,h2,p { font-family:"Helvetica"; } </style> </head> <body> <h1>Who is exporting weapons worldwide?</h1> <h2>Data about weapons export</h2> <script type="text/javascript"> //creates svg element named box var box = d3.select("body").append("svg").attr("width",800).attr("height",1400); //load the data and bind it to rectangles d3.csv("WeaponsExport19952014.csv", function(data) { var bars = box.selectAll("rect").data(data).enter().append("rect") //Filter the data to remove World check here https://bl.ocks.org/d3noob/8dc93bce7e7200ab487d .filter(function(d) { return d.Total < 174000 }); bars.attr("x",5) .attr("y",function(d,i) { return i*20; }) .attr("width", function(d) { return d.Total / 300; }) //.attr("width",100) .attr("height",18) .attr("fill","#9933FF"); //adding labels, anyway to bind the text to the rectangle without repeating data enter? var legend = box.selectAll("text").data(data).enter().append("text") .filter(function(d) { return d.Total < 180000 }); legend.attr("x",function(d) { return d.Total / 300+ 10; }) .attr("y",function(d,i) { return i*20 + 15; }) .text(function(d) { return d.Country; }) .attr("font-family", "Helvetica") .attr("font-size","12px") //.attr("width",100) .attr("fill","Grey") ; }); /* */ </script> </body> </html>
Modified
http://d3js.org/d3.v3.js
to a secure url
https://d3js.org/d3.v3.js