D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
almccon
Full window
Github gist
gapminder live demo
Built with
blockbuilder.org
<!DOCTYPE html> <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; }) console.log(filteredData); var xScale = d3.scaleLinear() .domain([0,1000000000]) .range([0,500]); var svgElements = svg.selectAll("g") .data(filteredData) .enter() .append("g"); svgElements .append("text") .text(function(d) { return d.country;}) .attr("y", function(d,i) { return 200+40*i;}) .attr("x", function(d) {return 100 + xScale(d.population);}); svgElements .append("rect") .attr("y", function (d,i) {return 176+40*i;}) .attr("x", 100) .attr("width", function (d) { return xScale(d.population); }) .attr("height",36) .attr("opacity",0.2) var bottomAxis = d3.axisBottom(xScale) .ticks(4); svg.append("g") .attr("transform", "translate(100,450)") .call(bottomAxis); }) </script> </body>
https://d3js.org/d3.v4.min.js