Last active
February 9, 2016 01:14
-
-
Save mbostock/1849162 to your computer and use it in GitHub Desktop.
Month Axis
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 path, | |
.axis line { | |
fill: none; | |
stroke: #000; | |
shape-rendering: crispEdges; | |
} | |
</style> | |
<body> | |
<script src="//d3js.org/d3.v3.min.js"></script> | |
<script> | |
var margin = {top: 10, right: 10, bottom: 20, left: 10}, | |
width = 960 - margin.left - margin.right, | |
height = 80 - margin.top - margin.bottom; | |
var x = d3.time.scale() | |
.domain([new Date(2012, 0, 1), new Date(2012, 11, 31)]) | |
.range([0, width]); | |
var xAxis = d3.svg.axis() | |
.scale(x) | |
.orient("bottom") | |
.ticks(d3.time.months) | |
.tickSize(16, 0) | |
.tickFormat(d3.time.format("%B")); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width + margin.left + margin.right) | |
.attr("height", height + margin.top + margin.bottom) | |
.append("g") | |
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); | |
svg.append("g") | |
.attr("class", "x axis") | |
.attr("transform", "translate(0," + height + ")") | |
.call(xAxis) | |
.selectAll(".tick text") | |
.style("text-anchor", "start") | |
.attr("x", 6) | |
.attr("y", 6); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment