Last active
February 9, 2016 00:18
-
-
Save mbostock/1071269 to your computer and use it in GitHub Desktop.
Date Ticks
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
license: gpl-3.0 |
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> | |
.axis text { | |
font: 10px sans-serif; | |
} | |
.axis line, | |
.axis path { | |
fill: none; | |
stroke: #000; | |
shape-rendering: crispEdges; | |
} | |
</style> | |
<body> | |
<script src="//d3js.org/d3.v3.min.js"></script> | |
<script> | |
var duration = 2500, | |
delay = 500; | |
var width = 960, | |
height = 500; | |
var x = d3.time.scale() | |
.domain([new Date(2010, 0, 2), new Date(2010, 1, 1)]) | |
.range([0, width]); | |
var xAxis = d3.svg.axis() | |
.scale(x) | |
.orient("bottom") | |
.tickSize(6, 0) | |
.tickFormat(d3.time.format("%m/%d")); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
var g = svg.append("g") | |
.attr("class", "axis") | |
.attr("transform", "translate(0," + height / 2 + ")") | |
.call(xAxis); | |
setInterval(update, duration + delay); | |
function update() { | |
x.domain([new Date(2010, 0, 2), new Date(2010, 0, Math.floor(Math.random() * 21) + 10)]); | |
g.transition() | |
.duration(duration) | |
.call(xAxis); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment