Skip to content

Instantly share code, notes, and snippets.

@lucguillemot
Created February 28, 2017 07:35
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 lucguillemot/bb13928730f50b16d098ec1b0f6b23e5 to your computer and use it in GitHub Desktop.
Save lucguillemot/bb13928730f50b16d098ec1b0f6b23e5 to your computer and use it in GitHub Desktop.
fresh block
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<button onclick=updateData()>update</button>
<script>
var svg = d3.select("body").append("svg")
.attr("width", 960)
.attr("height", 500);
var data = [4, 8, 16, 20];
var data2 = [10, 20, 30, 40];
var height =300;
var viz = svg.selectAll("circle")
.data(data).enter()
.append("circle")
.attr("cx", function(d, i) {return d*10;})
.attr("cy", 100)
.attr("r", function(d, i) {return d;})
.style("fill", "steelblue");
var rect = svg.selectAll("rect")
.data(data2).enter()
.append("rect")
.attr("x", function(d) { return d*10; })
.attr("width", 10)
.attr("y", 300)
.attr("height", function(d) { return d; })
.attr("fill", "#f00")
.attr("stroke", "#0ff")
.attr("stroke-width", 1);
function updateData() {
rect.transition().duration(3000)
.attr("fill", "#0f0")
.attr("width", Math.random())
.attr("height", function(d) { return d*3; });
}
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment