D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
EstelleWalt
Full window
Github gist
Celsa
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <style> text {fill:black} body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } circle{opacity:0.7} </style> </head> <body> <svg style="background:lightgrey" width=900 height=500></svg> <script> // Feel free to change or delete any of the code you see in this editor! var data = [ ] d3.select("body") .selectAll("text") .data (data) .enter() .append("p") .text(d=>d.nom) .style("background-color",d=>d.couleur) //santé var y = d3.scaleLinear() .domain ([45,90]) .range ([450,50]) //richesse var x = d3.scaleLog() .domain([500,100000]) .range([50,800]) // population var r = d3.scaleSqrt() .domain([1, 1.5e9]) .range([2,40]) // continent var c = d3.scaleOrdinal() .range(d3.schemeCategory10) function afficher (error, data) { data = data.sort((a,b) => d3.descending(+a.population, +b.population) ) d3.select("svg") .selectAll("circle") .data (data) .enter() .append("circle") .style("fill",d=>d.couleur) .style("stroke","black") .attr("r",d => r(d.population)) .attr("cx",d => x(d.richesse)) .attr("cy",d=> y(d.sante)) .attr("fill",d=> c(d.continent)) } // Axes legendes = d3.select('svg') .append('g'); var xAxis = d3.axisBottom() .scale(x) .tickFormat(function (d, i) { if (i % 3 == 0) return d; }), yAxis = d3.axisLeft() .scale(y) .ticks(8); legendes.append("g") .attr("class", "x axis") .attr("transform", "translate(0," + 450 + ")") .call(xAxis) .append('text') .text('PIB par habitant') .attr('transform', 'translate(500,-8)') .attr('text-anchor', 'end'); legendes.append("g") .attr("class", "y axis") .attr("transform", "translate(50,0)") .call(yAxis) .append('text') .text('Espérance de vie à la naissance') .attr('transform', 'translate(5,70)') .attr('text-anchor', 'start'); d3.csv("recent.csv", afficher) </script> </body>
https://d3js.org/d3.v4.min.js