Built with blockbuilder.org
forked from almccon's block: country population barchart
xxxxxxxxxx
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<script>
d3.csv("gapminder_avg.csv", function(data) {
data.forEach(function(d) {
d.population = +d.population;
d.lifeexp = +d.lifeexp;
d.gdp = +d.gdp;
});
var filteredData = data
.filter(function(d) {return +d.population > 100000000;})
.sort(function(a,b) {return a.population < b.population;})
// Draw our bar chart using divs
d3.select("body").selectAll("div")
.data(filteredData)
.enter()
.append("div")
.style("width", function (d) {return (500 * d.population / 1000000000) + "px";})
.style("height","20px")
.style("margin","10px")
.style("background","lightgray")
.text(function(d) { return d.country});
});
</script>
</body>
https://d3js.org/d3.v4.min.js