Skip to content

Instantly share code, notes, and snippets.

@rveciana
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rveciana/cbd4c10fed8942c87332 to your computer and use it in GitHub Desktop.
Save rveciana/cbd4c10fed8942c87332 to your computer and use it in GitHub Desktop.
JSL 2015: Gráfico con transiciones
<!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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment