D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
Juanma-GP
Full window
Github gist
Ejercicio6
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> <script> const rectWidth = 41; var svg = d3.select("body") .append("svg") .attr("width", "400") .attr("height", "180") var svg = d3.select("svg") d3.csv("junioGAD3.csv").then(datos => { svg.selectAll("rect") .data(datos) .enter().append("rect") .attr("x",0) .attr("y",(d,i) => i * rectWidth) .attr("height",rectWidth) .attr("width",d => 2*d.escanos) .attr("fill", d => d.color) .attr("stroke", "rgb(255,255,255)") .attr("stroke-width", 2) svg.selectAll("text") .data(datos) .enter().append("text") .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") }) </script> </body>
https://d3js.org/d3.v5.min.js