Segundo ejemplo del taller Mapas web interactivos con D3.js en el programa de las 9as Jornadas SIG Libre .
Al ejemplo anterior, añadimos transiciones y textos.
Los datos son de la encuesta GAD3, del 9-13 de enero de 2015. Fuente: Wikipedia
Segundo ejemplo del taller Mapas web interactivos con D3.js en el programa de las 9as Jornadas SIG Libre .
Al ejemplo anterior, añadimos transiciones y textos.
Los datos son de la encuesta GAD3, del 9-13 de enero de 2015. Fuente: Wikipedia
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script> | |
var width = 960, | |
height = 500; | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
d3.csv("https://cdn.rawgit.com/rveciana/5919944/raw//encuesta.csv", function(d){ | |
var r = d3.scale.linear() | |
.domain([0, d3.max(d, function(d) { return parseFloat(d.Porcentaje); })]) | |
.range([1, 100]); | |
svg.selectAll("rect") | |
.data(d) | |
.enter() | |
.append("rect") | |
.attr("x", function(d, i) {return i*50;}) | |
.attr("y", 100) | |
.attr("width", 40) | |
.attr("height", 0) | |
.attr("fill", function(d){ return d3.rgb(d.Color).darker();}) | |
.transition() | |
.duration(1000) | |
.delay(function(d, i){return i * 200;}) | |
.ease("linear") | |
.attr("y", function(d) { return 100 - r(d.Porcentaje); }) | |
.attr("height", function(d) { return r(d.Porcentaje); }) | |
.attr("fill", function(d){ return d3.rgb(d.Color); }); | |
svg.selectAll(".partido") | |
.data(d) | |
.enter() | |
.append("text") | |
.attr("class","partido") | |
.text(function(d){return d.Partido;}) | |
.attr("x", 0) | |
.attr("y", 0) | |
.attr("transform", function(d, i) {return "translate("+((i*50)+26)+",95) rotate(-90)";}); | |
}); | |
</script> |