Last active
October 2, 2015 07:54
-
-
Save tts/6723dd06ca2c23c5d5da to your computer and use it in GitHub Desktop.
Languages spoken in Espoo: binding data. Exercise in Data Visualization and Infographics with D3 by Knight Center for Journalism in the Americas
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> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Languages spoken in age group under 6</title> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js" charset="utf-8"></script> | |
<style type="text/css"> | |
body { | |
font-family: Helvetica, Arial, sans-serif; | |
padding: 150px; | |
background-color: GhostWhite; | |
} | |
h1 { | |
font-size: 30px; | |
font-weight: bold; | |
color: SlateGray; | |
} | |
a { | |
text-decoration: none; | |
color: SkyBlue; | |
} | |
a:link { | |
text-decoration: none; | |
} | |
.leftborder { | |
padding: 25px; | |
border-left: solid 4px Silver; | |
} | |
#about { | |
font-size: small; | |
margin-right: 700px; | |
margin-left: 10px; | |
padding: 50px; | |
color: Tan; | |
} | |
svg .cityname { | |
fill: SlateBlue; | |
font-weight: bold; | |
font-size: 30px; | |
} | |
svg .axis path, | |
.axis line { | |
fill: none; | |
stroke: black; | |
shape-rendering: crispEdges; | |
} | |
svg .axis text { | |
font-family: sans-serif; | |
font-size: 11px; | |
} | |
svg rect:hover { | |
fill: SlateBlue; | |
} | |
</style> | |
</head> | |
<body> | |
<h1 class="leftborder">Languages spoken in age group under 6</h1> | |
<!-- http://www.d3noob.org/2013/07/arranging-more-than-one-d3js-graph-on.html --> | |
<div id="logo"> | |
<svg width="700" height="300" class="containerleft"> | |
<g stroke = "SkyBlue" stroke-width = "5" fill = "none"> | |
<path d="M200,100 a100,60 -30 1,0 100,100" /> | |
<path d="M200,100 a100,60 -30 1,1 100,100" /> | |
<path d="M353,120 a100,70 -10 1,0 10,110" /> | |
</g> | |
<text x="400" y="150" class="cityname">ESPOO</text> | |
<text x="400" y="175" class="cityname">ESBO</text> | |
</svg> | |
</div> | |
<div id="chart"></div> | |
<div id="about"> | |
<p>Source: <a href="http://www.hri.fi/fi/dataset/espoon-vaesto-aidinkielen-ja-ian-mukaan-tilastoalueittain-vuodenvaihteessa-2013-2014">Espoon väestö äidinkielen ja iän mukaan tilastoalueittain vuodenvaihteessa 2013/2014</a>. | |
Aineiston ylläpitäjä on Espoon kaupungin kehittämis- ja tutkimusyksikkö ja alkuperäinen tekijä Tilastokeskus. | |
Downloaded from <a href="http://www.hri.fi/">Helsinki Region Infoshare</a> by licence <a href="http://creativecommons.org/licenses/by/4.0/deed.fi">Creative Commons Nimeä 4.0 Kansainvälinen (CC BY 4.0)</a></p> | |
</div> | |
<script type="text/javascript"> | |
<!-- http://alignedleft.com/tutorials/d3/scales --> | |
<!-- A scale’s input domain is the range of possible input data values. --> | |
<!-- A scale’s output range is the range of possible output values, commonly used as display values in pixel units. --> | |
<!-- What are max/min values of col 2? Reverted to unix command line this time: --> | |
<!-- cut -d ',' -f2 lang.csv | grep -v '[a-z]' | sort -n -r | head -n --> | |
<!-- cut -d ',' -f2 lang.csv | grep -v '[a-z]' | sort -n | head -n1 --> | |
var max = 19150; | |
var min = 19; | |
var h = 300; | |
var w = 900; | |
var padding = 20; | |
var scale = d3.scale.linear() | |
.domain([min, max]) | |
.range([15, 500]); | |
var svg = d3.select("#chart") | |
.append("svg") | |
.attr("width", w) | |
.attr("height", h); | |
var xAxis = d3.svg.axis() | |
.scale(scale) | |
.orient("bottom"); | |
d3.csv("lang.csv", function(data) { | |
data.sort(function(a, b) { | |
return d3.descending(+a.from0to6, +b.from0to6); | |
}) | |
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 scale(d.from0to6); | |
}) | |
.attr("height", 8) | |
.attr("fill", "Gainsboro") | |
.append("title") | |
.text(function(d) { | |
return d.Language + " is spoken by " + d.from0to6 + " children"; | |
}); | |
svg.append("g") | |
.attr("class", "axis") | |
.attr("transform", "translate(0," + (h - padding) + ")") | |
.call(xAxis); | |
}); | |
</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
Language | from0to6 | from7to15 | from16to29 | from30to44 | from45to64 | from65 | |
---|---|---|---|---|---|---|---|
Albanian | 218 | 211 | 389 | 316 | 177 | 16 | |
Arabic | 232 | 216 | 278 | 442 | 274 | 20 | |
Bengali | 61 | 35 | 162 | 201 | 31 | 0 | |
English | 275 | 164 | 432 | 833 | 392 | 79 | |
Spanish | 47 | 40 | 132 | 303 | 97 | 17 | |
Hindi | 74 | 34 | 76 | 248 | 23 | 5 | |
Chinese | 194 | 133 | 497 | 775 | 258 | 13 | |
Kurdish | 152 | 143 | 354 | 276 | 136 | 11 | |
Other | 550 | 429 | 1393 | 2214 | 849 | 199 | |
Persian | 67 | 72 | 258 | 194 | 126 | 36 | |
French | 43 | 36 | 70 | 170 | 73 | 10 | |
Romanian | 26 | 30 | 52 | 139 | 34 | 4 | |
Swedish | 2226 | 2642 | 3043 | 3440 | 4822 | 4102 | |
Somali | 421 | 442 | 615 | 337 | 213 | 29 | |
Finnish | 19150 | 22669 | 37250 | 44685 | 55350 | 29425 | |
Tagalog | 26 | 46 | 91 | 168 | 69 | 3 | |
Tamil | 75 | 20 | 86 | 151 | 13 | 1 | |
Telugu | 68 | 21 | 74 | 149 | 3 | 0 | |
Thai | 19 | 50 | 77 | 184 | 58 | 0 | |
Turkish | 54 | 39 | 109 | 174 | 102 | 21 | |
Hungarian | 53 | 48 | 59 | 171 | 46 | 11 | |
Urdu | 75 | 20 | 141 | 173 | 15 | 0 | |
Russian | 512 | 489 | 1054 | 1551 | 1086 | 178 | |
Vietnamese | 60 | 41 | 310 | 178 | 127 | 30 | |
Estonian | 459 | 429 | 1007 | 1632 | 1328 | 92 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment