D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
aaizemberg
Full window
Github gist
el ejemplo que hicimos hoy durante la clase
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title></title> <script src="https://d3js.org/d3.v4.min.js"></script> <style> rect { fill: steelblue; } </style> </head> <body> <h1>los seguidores de:</h1> <script> var datos = [ {"candidato":"cristina","seguidores":4867517}, {"candidato":"macri","seguidores":3937615}, {"candidato":"randazo","seguidores":465163} ]; var svg = d3.select("body").append("svg") .attr("width",400) .attr("height",200); svg.selectAll("text") .data(datos) .enter() .append("text") .attr("x",10) .attr("y", function(d,i) {return 50*i+50; } ) .text( function(d,i) { return d.candidato; } ); var escala = d3.scaleLinear().domain([0,4867517]).range([0,300]); svg.selectAll("rect") .data(datos) .enter() .append("rect") .attr("rx",10) .attr("ry",10) .attr("x",100) .attr("y", function(d,i) {return 50*i+40; } ) .attr("width", function(d,i) {return escala(d.seguidores)} ) .attr("height", 20) .append("title") .text( function(d,i) {return d.seguidores} ); </script> </body> </html>
https://d3js.org/d3.v4.min.js