Skip to content

Instantly share code, notes, and snippets.

@eesur
Last active August 29, 2015 13:57
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 eesur/9639834 to your computer and use it in GitHub Desktop.
Save eesur/9639834 to your computer and use it in GitHub Desktop.
d3 | random radius
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Random radius</title>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/d3/3.4.2/d3.js"></script>
</head>
<body>
<script>
var dataset = [];
for (var i = 0; i < 108; i++) {
var newNumber = Math.floor((Math.random()*100)+10);;
dataset.push(newNumber);
}
var w = 520, h = 520;
var duration = 520;
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
var circle = svg.append("circle")
.attr("cx", w/2)
.attr("cy", h/2)
.attr("fill", "black");
var label = svg.append("text")
.attr("x", "10")
.attr("y", "20")
.attr("font-family", "monospace")
.attr("font-size", "18px")
.attr("fill", "red");
dataset.forEach(function(d, i) {
circle.transition().duration(duration).delay(i * duration)
.attr("r", d);
label.transition().duration(duration).delay(i * duration)
.text(function (d) { return dataset[i] });
});
</script>
</body>
</html>
@eesur
Copy link
Author

eesur commented Mar 19, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment