D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
almccon
Full window
Github gist
gapminder 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> // Feel free to change or delete any of the code you see in this editor! var svg = d3.select("body") .append("svg") .attr("width", 960) .attr("height", 500); d3.csv("gapminder_avg.csv",function(dataWeLoaded) { //console.log(dataWeLoaded); var xScale = d3.scaleLinear() .domain([0,40000]) .range([100,800]); var yScale = d3.scaleLinear() .domain([30,80]) .range([400,100]); var rScale = d3.scaleSqrt() .domain([0,d3.max(dataWeLoaded, function(d) { return +d.population;})]) .range([0,100]); svg.selectAll("circle") .data(dataWeLoaded) .enter() .append("circle") .attr("cy", function(d) { return yScale(+d.lifeexp);}) //return 500-(d.lifeexp*6);}) .attr("cx", function(d) { return xScale(+d.gdp);}) //return 100+(d.gdp/100);}) .attr("r", function(d) { return rScale(+d.population) /* 1 + (d.population/10000000); */ }) .attr("fill-opacity",0.4) .attr("stroke","black") .attr("stroke-width",2) .attr("stroke-opacity",1) .attr("fill","firebrick") /* data.sort(function(a,b) { return +a.population > +b.population;}) .forEach(function(innerdata,i) { console.log(innerdata); svg.append("text") .text(innerdata.country) .attr("y", 135+(i*10)) .attr("x", 120) .attr("font-size", 12) .attr("fill", '#0000ff') .attr("font-family", "sans-serif") }) */ }) </script> </body>
https://d3js.org/d3.v4.min.js