Skip to content

Instantly share code, notes, and snippets.

@mbostock
Last active June 3, 2016 15:48
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 mbostock/1d96d9fdecf1b214f1395f94e0ba8758 to your computer and use it in GitHub Desktop.
Save mbostock/1d96d9fdecf1b214f1395f94e0ba8758 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<meta charset="utf-8">
<style>
#update {
position: absolute;
top: 10px;
left: 10px;
}
</style>
<button id="update">Update</button>
<svg width="960" height="500">
<g transform="translate(0,150)" id="axis"></g>
</svg>
<script src="https://d3js.org/d3.v4.0.0-alpha.44.min.js"></script>
<script>
var scale = d3.scaleLinear()
.rangeRound([100, 860]);
var axis = d3.axisBottom(scale);
d3.select("#update")
.on("click", clicked);
d3.select("#axis")
.call(update);
function clicked() {
d3.select("#axis")
.transition()
.call(update);
}
function update(group) {
scale.domain([0, Math.random() * 100]);
group.call(axis);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment