Skip to content

Instantly share code, notes, and snippets.

@Lampadaire
Created April 26, 2015 19:13
Show Gist options
  • Save Lampadaire/cc86c2f9a0090bf86543 to your computer and use it in GitHub Desktop.
Save Lampadaire/cc86c2f9a0090bf86543 to your computer and use it in GitHub Desktop.
Weapons export worldwide_step4
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Data on weapons exports in the world</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.js"></script>
<style type="text/css">
h1,h2,p {
font-family:"Helvetica";
}
.axis path,
.axis line {
fill: none;
stroke: black;
shape-rendering: crispEdges;
}
.axis text {
font-family: sans-serif;
font-size: 11px;
}
.y.axis path,
.y.axis line {
opacity: 0;
}
</style>
</head>
<body>
<h1>Who is exporting weapons worldwide?</h1>
<h2>Data about weapons exports</h2>
<script type="text/javascript">
//Defines a bunch of variables to be used later in the chart, makes life easier when wanting to change some stuff
//1 width and height of the svg element
var w = 700;
var h = 1800;
//2 padding variables, defines various white spaces in the chart
var padding = [ 20, 10, 30, 120 ]; //Top, right, bottom, left
//3 creates the scale for axis, the scale needs to be created before the axis itself
//linear scale, basically a scale for continuous numbers,range defines the length of the scale
var widthScale = d3.scale.linear()
.range([ 0, w-padding[1]-padding[3]]);
//console.log(widthScale);
//ordinal scale, basically a scale for categories,rangeRoundBands defines the position of the top and bottom cat. of the scale, O.1 the space
var heightScale = d3.scale.ordinal()
.rangeRoundBands([ padding[0], h - padding[2]], 0.1);
//4 creates both axis
var xAxis = d3.svg.axis()
.scale(widthScale)
.orient("top");
var yAxis = d3.svg.axis()
.scale(heightScale)
.orient("left");
//creates svg element named box
var svg = d3.select("body").append("svg").attr("width",w).attr("height",h);
//load the data and bind it to rectangles
d3.csv("WeaponsExport19952014.csv", function(data) {
var bars = svg.selectAll("rect").data(data).enter().append("rect");
//defines the input domain for the linear scale
widthScale.domain([ 0,d3.max(data, function(d) {
return +d.Total;
})]);
heightScale.domain(data.map(function(d) { return d.Country; } ));
bars.attr("x",padding[3])
.attr("y",function(d) {
return heightScale(d.Country);
})
.attr("width", function(d) {
return widthScale(d.Total);
})
//.attr("width",100)
.attr("height",heightScale.rangeBand())
.attr("fill","#9933FF")
.append("title")
.text(function(d) {
return d.Country + "'s total weapons exports for the period 1995-2014 is " + d.Total + " TIV";
});
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(" + padding[3] + "," + padding[0] + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.attr("transform", "translate(" + padding[3] + ",0)")
.call(yAxis);
});
/* */
</script>
</body>
</html>
Country 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 Total
United States 11146 10808 14518 15708 11553 7591 5682 4955 5618 6752 6758 7521 7834 6814 6822 8169 9111 9018 7384 10194 173956
Russia 3900 3539 3353 2046 4264 4546 5427 5635 5307 6250 5227 5113 5561 6264 5102 5993 8556 8402 8462 5971 108918
France 967 1896 3230 3139 1859 1116 1455 1474 1441 2324 1842 1702 2408 2063 1959 911 1770 1067 1578 1978 36179
Germany (FRG) 1468 1974 955 1837 1871 1619 923 916 1731 1139 2081 2710 3257 2388 2547 2725 1359 1161 942 1200 34803
United Kingdom 1493 1677 2418 1428 1380 1638 1392 1102 752 1221 1069 995 984 990 1021 1101 1010 930 1484 1704 25789
China 1013 769 435 353 332 302 515 518 693 386 281 643 479 591 1138 1459 1336 1666 2068 1083 16060
Italy 297 326 454 426 504 204 243 468 355 251 825 527 713 393 493 524 939 828 953 786 10509
Netherlands 473 499 614 622 349 284 203 233 336 218 526 1155 1210 460 485 381 538 783 357 561 10287
Ukraine 167 260 558 708 731 270 511 307 295 198 291 542 623 378 377 470 534 1450 708 664 10042
Israel 166 285 246 229 190 387 439 572 442 677 509 399 529 347 734 647 587 530 756 824 9495
Sweden 197 352 107 340 392 375 914 171 526 303 537 397 342 457 419 664 705 488 407 394 8487
Spain 82 105 625 170 43 46 8 16 95 52 108 840 601 602 961 277 1437 546 733 1110 8457
Switzerland 139 186 118 210 273 174 206 157 181 249 247 286 295 461 227 238 310 250 193 350 4750
Canada 263 159 95 40 79 74 129 172 267 270 228 228 338 229 180 242 321 341 258 234 4147
South Korea 27 64 60 72 0 10 228 0 96 73 108 158 279 178 269 197 331 218 235 153 2756
Belarus 7 129 356 63 458 293 49 63 57 19 53 43 6 224 41 159 97 65 268 0 2450
South Africa 17 31 7 24 27 20 37 17 43 72 30 184 126 139 103 235 71 181 95 59 1518
Belgium 167 59 93 46 45 26 37 37 15 47 146 59 19 217 243 9 111 22 65 0 1463
Poland 176 46 21 1 64 45 81 56 81 47 18 282 163 73 75 28 8 13 142 27 1447
Norway 21 4 19 3 5 3 42 83 84 56 6 17 61 114 147 159 156 158 122 127 1387
Turkey 3 3 0.25 3 43 19 5 26 42 28 14 73 42 97 63 72 86 143 146 274 1182.25
Finland 26 9 10 34 28 12 33 34 44 34 47 137 77 77 51 58 40 110 83 84 1028
Uzbekistan 0 0 0 0 0 0 0 0 252 126 4 0 0 0 209 209 209 0 0 0 1009
Czech Republic 131 114 22 20 55 80 87 60 64 1 73 44 32 32 22 5 11 8 34 17 912
Australia 36 16 20 4 0 0 43 47 44 2 49 14 18 25 72 115 143 75 54 104 881
North Korea 41 47 47 81 55 58 73 162 134 47 20 20 20 20 20 0 0 0 0 1 846
Brazil 33 23 23 16 0 0 0 26 0 46 1 44 53 92 43 151 31 33 40 47 702
Austria 0 0 13 23 35 36 29 95 3 3 4 63 100 15 42 48 46 21 24 19 619
Slovakia 97 60 55 10 125 37 53 31 0 46 0 7 22 8 0 0 0 4 0 0 555
Bulgaria 1 21 6 39 167 2 10 32 46 19 86 5 9 4 16 4 2 7 21 4 501
Moldova 0 0 217 0 0 6 42 60 10 0 18 3 19 29 20 0 11 0 0 0 435
Japan 158 188 32 0 0 0 0 0 0 0 0 0 40 0 0 0 0 0 0 0 418
Denmark 8 0 0 1 6 20 1 10 62 173 0 9 6 17 14 8 21 23 9 13 401
Jordan 0 0 6 0 0 0 0 0 0 42 20 0 13 12 60 111 0 20 1 114 399
Iran 1 2 1 0.25 0.25 0.25 0.25 3 9 1 2 75 0 43 45 45 86 21 12 42 389
Libya 0 0 3 10 0 0 0 21 16 113 113 18 10 18 32 28 0 0 0 0 382
Unknown country 1 75 10 3 2 11 23 21 14 10 44 3 0.25 35 13 28 3 20 5 30 351.25
Romania 9 4 11 2 19 3 0 0 24 0 3 8 32 0 2 1 0.25 108 108 2 336.25
Singapore 0 0.25 46 23 11 11 0 4 0 66 3 0 0 0 31 24 13 76 1 2 311.25
Kazakhstan 13 12 3 6 183 19 12 0 0 5 0 6 0 0 0 0 0 0 0 0 259
India 2 0.25 0.25 0.25 0.25 21 2 0.25 4 27 19 33 21 11 27 5 3 0 11 55 242.25
UAE 28 6 32 0 0 0 0 0 0 3 11 17 3 1 34 39 3 0 43 2 222
Ireland 0 0 0 0 0 0 0 0 0 0 15 30 29 26 26 25 1 25 31 8 216
Georgia 0 0 0 0 46 69 0 69 0 16 0 0 0 0 0 0 0 0 0 0 200
Kyrgyzstan 57 0 0 0 0 0 0 0 92 0 0 18 18 14 0 0 0 0 0 0 199
Montenegro 0 0 0 0 0 0 0 0 0 0 0 71 109 0 0 18 0 0 0 0 198
Indonesia 25 0 8 0 49 0 16 49 0 25 8 8 0 1 0 0 8 0 0 0 197
Hungary 6 0 24 0 0 0 0 34 0 0 82 0 9 0 0 0 0 0 41 0 196
Serbia 0 20 5 0 0 0 11 0 0 0 0 5 5 45 1 31 4 11 29 29 196
Portugal 0 0 0 0 0 0 0 0 0 0 0 0 0 99 46 0 0.25 0.25 0 18 163.5
Chile 0 29 0 2 1 1 0 1 0 0 0 0 0 100 0 0 0 0 0 20 154
Greece 0 19 31 9 3 2 2 0 6 22 13 23 0 0 0 0 0 0 0 0 130
Thailand 0 0 0 0 0 0 0 0 7 7 0 93 0 0 0 0 0 0 0 0 107
Kuwait 0 0 0 99 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 99
Saudi Arabia 0 1 0 0 0 0 0 0 0 0 0 18 0 0 0 1 62 0 0 0 82
New Zealand 0 0 0 0 1 1 0 1 0 1 0.25 0 0 0 0 0 0 75 0 0 79.25
Pakistan 0 0 0 0 0 3 1 9 8 9 24 4 0 1 0 0 0 0 0 0 59
Venezuela 0 0 0 0 0 0 0 0 0 1 0 7 0 3 40 0 0 0 0 0 51
Lebanon 0 0 0 0 0 0 0 45 0 0 0 0 0 0 0 0 0 0 0 0 45
Syria 0 0.25 0.25 0 0 0 0 0 0 0 0 3 0 0 20 20 0 0 0 0 43.5
Cyprus 0 43 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 43
Taiwan (ROC) 0 4 5 0 0 0 6 0.25 0 0 0 0 0 0 16 0 0 2 0 0 33.25
Brunei 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 24 0 0 0 24
Egypt 9 5 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 19
Peru 0 0 0 0 0 0 14 0 0 5 0 0 0 0 0 0 0 0 0 0 19
Ghana 0 0 0 0 0 0 0 0 0 0 19 0 0 0 0 0 0 0 0 0 19
Aruba 0 18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18
Bosnia and Herzegovina 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 14 0 0 0 18
Ethiopia 0 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17
Argentina 5 0 0 0 0 2 6 0 0 0 0 2 0 0 0 0 1 0 0 0 16
Qatar 0 0 0 0 9 0 0 0 0 0 0 6 0 0 0 0 0 0 0 0 15
Viet Nam 0 0 0 0 0 0 0 0 0 0 0 14 0 0 0 0 0 0 0 0 14
Malaysia 0.25 0 0 0 11 0 0 0 0 0 0 0 0 0 0.25 0 0 0 0 0 11.5
Sudan 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 0 11
Malta 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 10
Botswana 0 0 0 0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 0 0 0 0 0 0.25 0 0 0 0 0 0 0 0.25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment