D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
aaizemberg
Full window
Github gist
datafest 2016 (FN)
<!DOCTYPE html> <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>datafest 2016</title> </head> <body> <script> var data = [ {"ages":"20-25","englishmen":8.4,"english_soldiers":17.0}, {"ages":"25-30","englishmen":9.2,"english_soldiers":18.3}, {"ages":"30-35","englishmen":10.2,"english_soldiers":18.4}, {"ages":"35-40","englishmen":11.6,"english_soldiers":19.3} ]; var ancho = d3.scale.linear().domain([0,20]).range([0,400]); var svg = d3.select("body").append("svg").attr("width",600).attr("height",600); svg.selectAll("ages").data(data).enter().append("text") .attr("x",20) .attr("y", function(d,i) {return ((i+1)*50);} ) .text( function(d) { return d.ages;}); svg.selectAll("rect1").data(data).enter().append("rect") .attr("x",100) .attr("y", function(d,i) {return ((i+1)*50);} ) .attr("width", function(d) {return ancho(d.englishmen);}) .attr("height",10); svg.selectAll("rect2").data(data).enter().append("rect") .attr("fill","red") .attr("x",100) .attr("y", function(d,i) {return ((i+1)*50)-12;} ) .attr("width", 0) .attr("height",10) .transition().duration(3000) .attr("width", function(d) {return ancho(d.english_soldiers);}); </script> </body> </html>
https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js