Skip to content

Instantly share code, notes, and snippets.

@aaizemberg
Created June 10, 2017 16:28
Show Gist options
  • Save aaizemberg/90e39c5dd5630517b6c016cfbd2123b8 to your computer and use it in GitHub Desktop.
Save aaizemberg/90e39c5dd5630517b6c016cfbd2123b8 to your computer and use it in GitHub Desktop.
el ejemplo que hicimos hoy durante la clase
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title></title>
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
rect {
fill: steelblue;
}
</style>
</head>
<body>
<h1>los seguidores de:</h1>
<script>
var datos = [
{"candidato":"cristina","seguidores":4867517},
{"candidato":"macri","seguidores":3937615},
{"candidato":"randazo","seguidores":465163}
];
var svg = d3.select("body").append("svg")
.attr("width",400)
.attr("height",200);
svg.selectAll("text")
.data(datos)
.enter()
.append("text")
.attr("x",10)
.attr("y", function(d,i) {return 50*i+50; } )
.text( function(d,i) { return d.candidato; } );
var escala = d3.scaleLinear().domain([0,4867517]).range([0,300]);
svg.selectAll("rect")
.data(datos)
.enter()
.append("rect")
.attr("rx",10)
.attr("ry",10)
.attr("x",100)
.attr("y", function(d,i) {return 50*i+40; } )
.attr("width", function(d,i) {return escala(d.seguidores)} )
.attr("height", 20)
.append("title")
.text( function(d,i) {return d.seguidores} );
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment