Classic D3 Examples
Old school D3 from simpler times
rafa79
Full window
Github gist
fresh block
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v5.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } .barras div { margin: 2px; padding: 10px; text-align: right; color: white; } </style> </head> <body> <h1>BarĂ³metro Junio GAD3</h1> <svg width="400" height = "180" class="barras_svg>" <rect/> <rect/> <rect/> <rect/> <text/> <text/> <text/> <text/> </svg> <div class=barras> <div></div> <div></div> <div></div> <div></div> </div> <script> const rectWidth = 40; d3.csv("junioGAD3.csv").then(datos => { //console.table(datos) d3.selectAll(".barras_svg rect") .data(datos) .attr("x", 0) .attr("y", (d,i) => i * rectWidth) .attr("height", rectWidth) //anchura .attr("width", d => 2*d.escanos) .attr("fill", d => d.color) .attr("stroke", "rgb(255,255,255)") .attr("stroke-width", 2) d3.selectAll(".barras_svg text") .data(datos) .text(d => d.nombre) .attr("x", d => 2*d.escanos) .attr("dx","-10") .attr("y", (d,i) => (i + 0.5) * rectWidth) .attr("fill", "rgb(255,255,255)") .attr("text-anchor", "end") .attr("alignment-baseline", "central") //me dice una propiedad del texto si estoy centrado }) //console.log(a) d3.csv("junioGAD3.csv").then(datos => { d3.selectAll(".barras div") .data(datos) .text(d => d.nombre) .style("background-color", d => d.color) .style("width", d => 2*d.escanos + 'px') }); </script> </body>
https://d3js.org/d3.v5.min.js