Very simple example of using D3 transitions to move some circles and change their colors
Simple Transition
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> | |
<meta charset="utf-8"> | |
<style> | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script> | |
var data = [2,4,3]; | |
var width = 800; | |
var height = 500; | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
svg.selectAll("circle") | |
.data(data) | |
.enter().append("circle") | |
.attr("r", function(d) { return 5 * d; }) | |
.attr("fill", "red") | |
.attr("cx", 40) | |
.attr("cy", height / 2); | |
svg.selectAll("circle") | |
.transition() | |
.duration(750) | |
.delay(500) | |
.attr("fill", "green") | |
.attr("cx", 500) | |
.attr("cy", function(d, i) { return 100 * (i + 1); }); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment