Last active
October 14, 2016 16:06
-
-
Save jashcny/cdc956dc33d83d39c74e to your computer and use it in GitHub Desktop.
Week 2: Paragraph Data load
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<!-- This was one of Scott Murray's Knight D3 course files, modified a bit. --> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Loading CSV Data with D3</title> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script> | |
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.0.min.js"></script> | |
</head> | |
<body> | |
<h1>Loading CSV and JSON with D3.</h1> | |
<p>Look in the console for logging info after the data loads.</p> | |
<p>If you open the console after loading, you'll need to reload the page.</p> | |
<p>We're printing the contents of the files to the screen here, just to show they load. | |
<p class="csvdata"></p> | |
<p class="jsondata"></p> | |
<script> | |
var body = d3.select("body") | |
//Load in contents of CSV file | |
d3.csv("kidnapping.csv", function(data1) { | |
//Now CSV contents have been transformed into | |
//an array of JSON objects. | |
console.log("The first file is csv...") | |
//Log 'data' to the console, for verification. | |
console.log(data1); | |
console.log("My first object:",data1[0]); | |
data1.forEach(function (d) { | |
body.append("p").text(d.Region + " " + d.SubRegion + " " + d.City + " " + d.Year2003 + " " + d.Year2004 + " " + d.Year2005 + " " +d.Year2006 + " " +d.Year2007 + " " +d.Year2008 + " " +d.Year2009 + " " + d.Year2010 + " " + d.Year2011 + " " + d.Year2012 + " " + d.Year2013); | |
}); | |
}); | |
// Notice that the objects look the same. d3.csv() parses rows as objects. | |
// Also this is a good point to talk about scope and breakpoints. | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Region | SubRegion | City | Year2003 | Year2004 | Year2005 | Year2006 | Year2007 | Year2008 | Year2009 | Year2010 | Year2011 | Year2012 | Year2013 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Africa | Eastern Africa | Burundi | 24 | 31 | 24 | 49 | 49 | 58 | ||||||
Africa | Eastern Africa | Kenya | 235 | 152 | 220 | 173 | 73 | 95 | 79 | 55 | 75 | 59 | ||
Africa | Eastern Africa | Mauritius | 34 | 35 | 50 | |||||||||
Africa | Eastern Africa | Rwanda | 8 | 8 | 12 | 12 | 10 | 21 | ||||||
Africa | Eastern Africa | Uganda* | 54 | 65 | 202 | |||||||||
Africa | Eastern Africa | Zimbabwe | 139 | 198 | 43 | 90 | 256 | 222 | ||||||
Africa | Middle Africa | Sao Tome and Principe | 0 | 0 | 0 | 0 | 0 | |||||||
Africa | Northern Africa | Algeria | 220 | 149 | 101 | 302 | 241 | 205 | 207 | 177 | 168 | 106 | 223 | |
Africa | Northern Africa | Egypt | 16 | 21 | 18 | 29 | 36 | 47 | 70 | 93 | 273 | |||
Africa | Northern Africa | Morocco | 392 | 342 | 295 | 264 | 233 | 217 | 307 | 556 | 974 | |||
Africa | Northern Africa | Sudan | 616 | |||||||||||
Africa | Southern Africa | Botswana | 3 | 3 | 5 | |||||||||
Africa | Southern Africa | Lesotho | 64 | 40 | 62 | |||||||||
Africa | Southern Africa | Swaziland | 122 | 96 | ||||||||||
Africa | Western Africa | Cabo Verde | 6 | 7 | 22 | 28 | ||||||||
Africa | Western Africa | Guinea | 14 | 4 | 16 | 0 | 18 | 25 | ||||||
Africa | Western Africa | Nigeria | 277 | 309 | 703 | 738 | 600 | 574 | ||||||
Americas | Caribbean | Bahamas | 24 | 27 | 31 | 35 | 27 | 18 | 26 | 28 | ||||
Americas | Caribbean | Barbados | 12 | 23 | 14 | 17 | 12 | 18 | 12 | 13 | 9 | 8 | ||
Americas | Caribbean | Dominican Republic | 20 | 14 | 19 | |||||||||
Americas | Caribbean | Grenada | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||
Americas | Caribbean | Jamaica | 31 | 38 | 38 | 43 | 11 | 21 | ||||||
Americas | Caribbean | St. Kitts and Nevis | 2 | 2 | 3 | |||||||||
Americas | Caribbean | St. Vincent and the Grenadines | 3 | 2 | 3 | 8 | 2 | 1 | 2 | 5 | 4 | |||
Americas | Caribbean | Trinidad and Tobago | 28 | 58 | 17 | 14 | 17 | 8 | 7 | 3 | 3 | 4 | ||
Americas | Central America | Belize | 9 | 8 | 2 | 3 | ||||||||
Americas | Central America | Costa Rica | 5 | 8 | 11 | 6 | 8 | 8 | 5 | 11 | 12 | 5 | 4 | |
Americas | Central America | El Salvador | 4 | 8 | 21 | 10 | 22 | 29 | 15 | 14 | 14 | |||
Americas | Central America | Guatemala | 51 | 52 | 57 | 98 | 213 | 162 | 133 | 124 | 83 | |||
Americas | Central America | Honduras | 37 | 79 | 51 | |||||||||
Americas | Central America | Mexico | 169 | 323 | 325 | 595 | 438 | 907 | 1,162 | 1,284 | 1,344 | 1,512 | 1,888 | |
Americas | Central America | Nicaragua | 11 | 6 | 7 | |||||||||
Americas | Central America | Panama* | 11 | 17 | 13 | 29 | 21 | 28 | 38 | 25 | 17 | 216 | ||
Americas | Northern America | Bermuda* | 3 | 2 | ||||||||||
Americas | Northern America | Canada** | 3,198 | 3,457 | 3,896 | 4,488 | 4,660 | 4,732 | 4,791 | 4,301 | 3,780 | 3,637 | 3,239 | |
Americas | South America | Bolivia (Plurinational State of) | 99 | 143 | 160 | 125 | 111 | 91 | 104 | 104 | ||||
Americas | South America | Brazil | 525 | 516 | 290 | 552 | 401 | 319 | 414 | 396 | ||||
Americas | South America | Chile* | 161 | 114 | 151 | 247 | 254 | 266 | 246 | 259 | 327 | 254 | ||
Americas | South America | Colombia | 1,442 | 800 | 687 | 521 | 437 | 213 | 282 | 305 | 305 | 299 | ||
Americas | South America | Ecuador | 257 | 203 | 37 | 47 | ||||||||
Americas | South America | Guyana | 1 | 2 | 2 | 1 | 0 | 0 | ||||||
Americas | South America | Paraguay | 1 | 5 | 4 | 9 | 3 | 2 | 0 | 3 | ||||
Americas | South America | Peru* | 275 | 469 | 497 | 611 | 463 | 483 | 726 | |||||
Americas | South America | Uruguay | 3 | 19 | 20 | |||||||||
Asia | Central Asia | Kazakhstan | 92 | 84 | 84 | 89 | 120 | 124 | 196 | 80 | 107 | |||
Asia | Central Asia | Kyrgyzstan | 17 | 24 | 24 | 13 | 34 | 25 | 6 | 84 | 54 | 60 | 41 | |
Asia | Central Asia | Tajikistan | 199 | 181 | 188 | 155 | 146 | 172 | ||||||
Asia | Central Asia | Turkmenistan | 157 | 127 | ||||||||||
Asia | Eastern Asia | Hong Kong Special Administrative Region of China | 0 | 1 | 0 | 0 | 3 | 0 | 0 | 1 | 0 | 0 | 1 | |
Asia | Eastern Asia | Japan | 284 | 320 | 277 | 199 | 207 | 156 | 156 | 186 | 153 | 190 | 185 | |
Asia | Eastern Asia | Macao Special Administrative Region of China* | 0 | 0 | 2 | 0 | 0 | 1 | ||||||
Asia | Eastern Asia | Mongolia | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 2 | |
Asia | Eastern Asia | Republic of Korea | 127 | 155 | 259 | 298 | 222 | 256 | 195 | |||||
Asia | South-Eastern Asia | Brunei Darussalam | 1 | 1 | 0 | 0 | ||||||||
Asia | South-Eastern Asia | Indonesia | 621 | 485 | 398 | 454 | 395 | 361 | ||||||
Asia | South-Eastern Asia | Philippines | 90 | 42 | 44 | 28 | 35 | 46 | 35 | 21 | 11 | 29 | ||
Asia | South-Eastern Asia | Singapore | 3 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | |||
Asia | South-Eastern Asia | Thailand | 12 | 11 | 21 | 16 | 5 | |||||||
Asia | Southern Asia | Bangladesh | 1,303 | 1,119 | ||||||||||
Asia | Southern Asia | Bhutan | 2 | 1 | 0 | 2 | 1 | |||||||
Asia | Southern Asia | India | 23,327 | 22,832 | 23,991 | 27,561 | 30,261 | 33,860 | 38,440 | 44,664 | 47,592 | 65,461 | ||
Asia | Southern Asia | Maldives | 1 | 2 | 5 | 14 | 26 | 19 | 17 | 8 | ||||
Asia | Southern Asia | Nepal | 123 | 246 | ||||||||||
Asia | Southern Asia | Sri Lanka | 829 | 868 | 526 | 358 | 202 | 180 | 222 | 195 | ||||
Asia | Western Asia | Armenia | 23 | 22 | 26 | 26 | 27 | 34 | 39 | 34 | 38 | |||
Asia | Western Asia | Azerbaijan | 28 | 23 | 29 | 21 | 19 | 20 | 19 | 9 | 1 | 9 | ||
Asia | Western Asia | Bahrain | 5 | 18 | 12 | 21 | 0 | |||||||
Asia | Western Asia | Cyprus | 20 | 15 | 16 | 15 | 10 | 12 | 26 | 27 | 25 | 30 | 19 | |
Asia | Western Asia | Georgia | 94 | 88 | 34 | 11 | 5 | 9 | 4 | |||||
Asia | Western Asia | Israel | 397 | 418 | 383 | 337 | 340 | 267 | 265 | |||||
Asia | Western Asia | Jordan | 28 | 34 | ||||||||||
Asia | Western Asia | Kuwait | 285 | 280 | 278 | 329 | 327 | 358 | ||||||
Asia | Western Asia | Lebanon | 899 | 938 | 937 | 1,059 | 1,308 | 1,484 | ||||||
Asia | Western Asia | Oman | 13 | 9 | ||||||||||
Asia | Western Asia | Qatar | 7 | 6 | ||||||||||
Asia | Western Asia | State of Palestine* | 126 | 167 | 202 | 83 | 23 | 21 | 24 | 12 | ||||
Asia | Western Asia | Syrian Arab Republic | 85 | 135 | 42 | 54 | 15 | 24 | ||||||
Asia | Western Asia | Turkey | 7,753 | 7,624 | 8,737 | 10,519 | 9,455 | 10,764 | 12,700 | 13,586 | 13,584 | 13,431 | ||
Asia | Western Asia | United Arab Emirates | 434 | 506 | 862 | 971 | 73 | |||||||
Asia | Western Asia | Yemen | 102 | 27 | 26 | 48 | 41 | |||||||
Europe | Eastern Europe | Belarus | 30 | 34 | 36 | 23 | 31 | 19 | 16 | 19 | 12 | 6 | ||
Europe | Eastern Europe | Bulgaria | 209 | 192 | 190 | 125 | 138 | 127 | 142 | 118 | 77 | 75 | 87 | |
Europe | Eastern Europe | Czech Republic | 14 | 15 | 13 | 16 | 15 | 8 | 7 | 10 | 8 | 8 | 11 | |
Europe | Eastern Europe | Hungary | 36 | 19 | 7 | 13 | 7 | 11 | 14 | 18 | 12 | 9 | 7 | |
Europe | Eastern Europe | Poland | 110 | 117 | 22 | 23 | 25 | 37 | 59 | 26 | 11 | 27 | 445 | |
Europe | Eastern Europe | Republic of Moldova | 16 | 18 | 20 | 19 | 16 | 38 | 51 | 92 | 116 | |||
Europe | Eastern Europe | Romania | 321 | 272 | 280 | 289 | 287 | 265 | ||||||
Europe | Eastern Europe | Russian Federation | 1,117 | 1,135 | 994 | 837 | 698 | 633 | 519 | 520 | 512 | 442 | ||
Europe | Eastern Europe | Slovakia | 16 | 12 | 4 | 3 | 6 | 4 | 4 | 7 | 4 | |||
Europe | Eastern Europe | Ukraine | 205 | 172 | 178 | 233 | 256 | 279 | 338 | 292 | ||||
Europe | Northern Europe | Estonia | 2 | 1 | 2 | 1 | 2 | 2 | 0 | 0 | 3 | 0 | 1 | |
Europe | Northern Europe | Finland | 1 | 2 | 2 | 1 | 1 | 0 | 3 | 1 | 3 | 1 | 1 | |
Europe | Northern Europe | Ireland | 53 | 74 | 74 | 81 | 106 | 77 | 146 | 134 | 109 | 101 | 120 | |
Europe | Northern Europe | Latvia | 26 | 41 | 6 | 8 | 9 | 3 | 9 | 8 | 7 | 1 | 18 | |
Europe | Northern Europe | Lithuania | 37 | 62 | 70 | 60 | 66 | 61 | 59 | 69 | 48 | 65 | 46 | |
Europe | Northern Europe | United Kingdom (England and Wales) | 3,125 | 2,814 | 2,799 | 2,367 | 1,991 | 2,035 | 1,860 | 1,717 | 1,516 | 1,387 | 1,727 | |
Europe | Northern Europe | United Kingdom (Northern Ireland) | 71 | 80 | 46 | 53 | 67 | 83 | 82 | 56 | 66 | 45 | 59 | |
Europe | Northern Europe | United Kingdom (Scotland) | 353 | 347 | 343 | 284 | 319 | 269 | 260 | 219 | 227 | 253 | ||
Europe | Southern Europe | Albania | 13 | 13 | 10 | 5 | 9 | 2 | 2 | 5 | ||||
Europe | Southern Europe | Andorra | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||
Europe | Southern Europe | Bosnia and Herzegovina | 7 | 9 | 5 | 8 | 6 | 1 | 1 | 2 | 5 | |||
Europe | Southern Europe | Croatia | 14 | 20 | 7 | 14 | 16 | 12 | 13 | 6 | 6 | 1 | ||
Europe | Southern Europe | Greece | 24 | 25 | 28 | 30 | 30 | 16 | 173 | 158 | 139 | 95 | ||
Europe | Southern Europe | Italy | 132 | 154 | 368 | 278 | 364 | 325 | 349 | 351 | 356 | 341 | 325 | |
Europe | Southern Europe | Kosovo under UNSCR 1244 | 46 | 50 | 43 | 31 | 33 | 34 | ||||||
Europe | Southern Europe | Malta* | 0 | 0 | 0 | 0 | 0 | 0 | ||||||
Europe | Southern Europe | Montenegro | 4 | 2 | 3 | 3 | 2 | 3 | 0 | 1 | ||||
Europe | Southern Europe | Portugal | 446 | 438 | 556 | 443 | 492 | 539 | 501 | 507 | 419 | 432 | ||
Europe | Southern Europe | Serbia | 26 | 23 | 19 | 16 | 24 | 20 | 9 | 11 | 9 | |||
Europe | Southern Europe | Slovenia | 8 | 1 | 3 | 6 | 9 | 7 | 2 | 4 | 2 | 4 | 4 | |
Europe | Southern Europe | Spain | 208 | 223 | 216 | 237 | 171 | 127 | 111 | 118 | 121 | |||
Europe | Southern Europe | The former Yugoslav Rep. of Macedonia | 24 | 24 | 30 | 14 | 16 | 17 | 14 | 19 | 18 | |||
Europe | Western Europe | Austria | 3 | 5 | 4 | 5 | 11 | 5 | 9 | 5 | 11 | 4 | ||
Europe | Western Europe | Belgium | 1,003 | 1,066 | 919 | 915 | 958 | 1,013 | 1,080 | 1,121 | 1,187 | 1,170 | 1,135 | |
Europe | Western Europe | France | 2,031 | 2,143 | 2,012 | 2,288 | 2,109 | 2,074 | 2,085 | 2,092 | 2,234 | 2,117 | 2,266 | |
Europe | Western Europe | Germany | 1,830 | 1,727 | 1,596 | 1,825 | 1,857 | 1,810 | 1,699 | 1,688 | 1,643 | 1,702 | ||
Europe | Western Europe | Liechtenstein | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||
Europe | Western Europe | Luxembourg | 17 | 36 | 33 | 40 | 27 | 47 | ||||||
Europe | Western Europe | Monaco | 0 | 2 | ||||||||||
Europe | Western Europe | Netherlands* | 910 | 850 | 780 | 760 | 625 | 645 | 560 | 580 | 520 | |||
Europe | Western Europe | Switzerland* | 263 | 267 | 245 | 274 | 269 | 309 | 359 | 309 | 308 | 295 | 324 | |
Oceania | Australia and New Zealand | Australia* | 4,090 | 3,422 | 608 | 675 | 638 | 601 | ||||||
Oceania | Australia and New Zealand | New Zealand* | 289 | 351 | 338 | 342 | 302 | 229 | 278 | 235 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment