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>
var svg = d3.select("body").append("svg")
.attr("width", 960)
.attr("height", 500)
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;})
filteredData
.forEach(function(d,i) {
svg.append("text")
.text(d.country)
.attr("y", 200+40*i)
.attr("x", 100)
.attr("font-size", 20)
.attr("font-family", "sans-serif")
});
svg.selectAll("rect")
.data(filteredData)
.enter()
.append("rect")
.attr("y", function (d,i) {return 176+40*i;})
.attr("x", 100)
.attr("width", function (d) {return 500 * d.population / 1000000000;})
.attr("height",36)
.attr("opacity",0.2)
});
</script>
</body>
https://d3js.org/d3.v4.min.js