Skip to content

Instantly share code, notes, and snippets.

@pierandrea
Last active August 29, 2015 14:18
Show Gist options
  • Save pierandrea/372002cef580762b8ee9 to your computer and use it in GitHub Desktop.
Save pierandrea/372002cef580762b8ee9 to your computer and use it in GitHub Desktop.
#Knight D3 - Exercise Module 3 - Creating a bar chart
Country year2013 year2014
Afghanistan 0 1
Albania 6 16
Algeria 0 1
Andorra 0 3
Argentina 278 482
Armenia 1 1
Australia 603 829
Austria 28 46
Bahrain 1 3
Bangladesh 5
Belgium 154 239
Bhutan 1 0
Bosnia and Herzegovina 4 5
Botswana 1 0
Brazil 1165 1212
Bulgaria 2 0
Cambodia 1 0
Canada 174 279
Chile 230 288
Colombia 21 67
Costa Rica 9 1
Croatia 7 21
Cyprus 3 20
Czech Republic 14 22
Denmark 12 31
Dominican Republic 0 22
Ecuador 2 2
Egypt 6 5
Estonia 6 6
Finland 11 18
France 1661 2094
Georgia 3 0
Germany 1687 2132
Greece 115 117
Greenland 2 1
Hong Kong 25 39
Hungary 38 128
India 3598 5473
Indonesia 0 5
Ireland 35 34
Israel 129 232
Italy 1699 1774
Ivory Coast 1 0
Japan 0 9
Jordan 0 3
Kazakhstan 2 2
Kenya 0 2
Kosovo 1 2
Kuwait 4 4
Lebanon 12 0
Liechtenstein 0 2
Lithuania 9 12
Luxembourg 2 1
Macau 1 1
Macedonia 6 5
Malaysia 16 17
Maldives 0 3
Malta 81 93
Mexico 125 260
Moldova 0 4
Montenegro 0 4
Myanmar 0 0
Nepal 2 2
Netherlands 23 76
New Zealand 80 139
Norway 15 21
Oman 3 0
Pakistan 126 100
Palestine 4 0
Paraguay 0 2
Peru 2 10
Philippines 4 7
Poland 220 305
Portugal 148 305
Qatar 3 0
Romania 11 14
Russia 1 2
Senegal 0 1
Serbia 1 15
Singapore 141 177
Slovakia 5
Slovenia 3 3
South Africa 3 2
South Korea 1 14
Spain 404 500
Sri Lanka 1 0
Sudan 4 2
Sweden 89 213
Switzerland 34 39
Taiwan 193 204
Thailand 2 3
Tunisia 0 2
Turkey 129 165
Uganda 1 0
Ukraine 0 1
United Arab Emirates 2 2
United Kingdom 1906 2366
United States 12598 14274
Uruguay 1 2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>#KnightD3 - Exercise Module 3: Making a horizontal bar chart</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.js"></script>
<style type="text/css">
body {
background-color: orange;
font-family: tahoma, helvetica;
color: white;
padding: 20px;
}
svg {
background-color: orange;
}
div {
text-align: center;
}
h1 {
text-align: center;
}
p {
text-align: center;
}
p.italic {
font-style: italic;
font-size: 6;
}
</style>
</head>
<body>
<h1>Facebook Government Report</h1>
<p>Account data requests received by Facebook from governments around the world in 2013</P>
<script type="text/javascript">
var svg = d3.select("body")
.append("svg")
.attr("width", 800)
.attr("height", 400);
d3.csv("FacebookGovRep.csv", function(data) {
data.sort(function(a, b) {
return d3.descending(+a.year2013, +b.year2013);
});
var rects = svg.selectAll("rect")
.data(data)
.enter()
.append("rect");
rects.attr("x", 0)
.attr("y", function(d, i) {
return i * 10;
})
.attr("width", function(d) {
return d.year2013 / 10;
})
.attr("height", 8)
.append("title")
.text(function(d) {
return d.year2013 + " " + d.Country + "'s Government requests to Facebook";
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment