Last active
August 29, 2015 14:02
-
-
Save aaizemberg/fe57e231fe7e39410a59 to your computer and use it in GitHub Desktop.
Don't lie
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<meta charset="utf-8"> | |
<title>don't lie</title> | |
</head> | |
<body> | |
<div id="uno"></div> | |
<div id="dos"></div> | |
<script> | |
var datos = [25,50,100]; | |
var r = d3.scale.sqrt() | |
.domain([0, 100]) | |
.range([0, 50]); | |
var svg1 = d3.select("#uno") | |
.append("svg") | |
.attr("width", 400) | |
.attr("height", 100); | |
var svg2 = d3.select("#dos") | |
.append("svg") | |
.attr("width", 400) | |
.attr("height", 100); | |
svg1.selectAll("circle") | |
.data(datos) | |
.enter() | |
.append("circle") | |
.attr("r", function(d,i) { return d/2; } ) | |
.attr("cx", function(d,i) { return (i+1) * 100; } ) | |
.attr("cy", 50); | |
svg2.selectAll("circle") | |
.data(datos) | |
.enter() | |
.append("circle") | |
// sin usar scale/domain/range | |
// .attr("r", function(d,i) { return 5*Math.sqrt(d); } ) | |
// usando scale/domain/range con escala "sqrt" | |
.attr("r", r ) | |
// otra forma de escribir lo mismo | |
// .attr("r", function(d,i) { return r(d) } ) | |
.attr("cx", function(d,i) { return (i+1) * 100; } ) | |
.attr("cy", 50); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment