Skip to content

Instantly share code, notes, and snippets.

@aaizemberg
Created June 24, 2016 21:20
Show Gist options
  • Save aaizemberg/8ebe23d4e7127f76e8cd474d6944ad27 to your computer and use it in GitHub Desktop.
Save aaizemberg/8ebe23d4e7127f76e8cd474d6944ad27 to your computer and use it in GitHub Desktop.
datafest 2016 (FN)
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>datafest 2016</title>
</head>
<body>
<script>
var data = [
{"ages":"20-25","englishmen":8.4,"english_soldiers":17.0},
{"ages":"25-30","englishmen":9.2,"english_soldiers":18.3},
{"ages":"30-35","englishmen":10.2,"english_soldiers":18.4},
{"ages":"35-40","englishmen":11.6,"english_soldiers":19.3}
];
var ancho = d3.scale.linear().domain([0,20]).range([0,400]);
var svg = d3.select("body").append("svg").attr("width",600).attr("height",600);
svg.selectAll("ages").data(data).enter().append("text")
.attr("x",20)
.attr("y", function(d,i) {return ((i+1)*50);} )
.text( function(d) { return d.ages;});
svg.selectAll("rect1").data(data).enter().append("rect")
.attr("x",100)
.attr("y", function(d,i) {return ((i+1)*50);} )
.attr("width", function(d) {return ancho(d.englishmen);})
.attr("height",10);
svg.selectAll("rect2").data(data).enter().append("rect")
.attr("fill","red")
.attr("x",100)
.attr("y", function(d,i) {return ((i+1)*50)-12;} )
.attr("width", 0)
.attr("height",10)
.transition().duration(3000)
.attr("width", function(d) {return ancho(d.english_soldiers);});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment