An axis that uses a date scale (d3.scaleTime
) and has a specified number of ticks is apparently mislabelled.
Last active
April 15, 2016 10:51
-
-
Save robinhouston/8663e60242e88dea64231a6fd014a49f to your computer and use it in GitHub Desktop.
An axis with a date scale
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
height: 40 | |
border: no |
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> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>An axis with a date scale</title> | |
<script src="https://d3js.org/d3.v4.0.0-alpha.29.min.js"></script> | |
<style> | |
path.domain, .tick line { fill: none; stroke: black; } | |
</style> | |
</head> | |
<body> | |
<script> | |
var W = 600, M = 10; | |
var scale = d3.scaleTime().domain([ new Date(2012, 0, 1), new Date(2013, 0, 1) ]).range([0, W]), | |
axis = d3.axisBottom().scale(scale); | |
// If we do not specify a number of ticks, the axis is labelled with months as expected | |
axis.ticks(6); | |
d3.select(document.body) | |
.append("svg").attr("width", W + 2*M) | |
.append("g").attr("transform", "translate(" + M + "," + M + ")") | |
.call(axis); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment