Skip to content

Instantly share code, notes, and snippets.

@mbostock
Last active February 9, 2016 00:56
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/1399097 to your computer and use it in GitHub Desktop.
Save mbostock/1399097 to your computer and use it in GitHub Desktop.
Left-Aligned Ticks
license: gpl-3.0
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font: 10px sans-serif;
}
rect {
fill: #ddd;
}
.grid line {
stroke: #fff;
}
.grid line.minor {
stroke-width: .5px;
}
.grid text {
display: none;
}
.axis line {
stroke: #000;
}
path {
display: none;
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script>
var m = [10, 10, 20, 10],
w = 960 - m[1] - m[3],
h = 80 - m[0] - m[2],
x = d3.time.scale().domain([Date.UTC(2001, 0, 1), Date.UTC(2002, 0, 1)]).range([0, w]),
y = d3.scale.linear().range([0, h]);
var svg = d3.select("body").append("svg")
.attr("width", w + m[1] + m[3])
.attr("height", h + m[0] + m[2])
.append("g")
.attr("transform", "translate(" + m[3] + "," + m[0] + ")");
svg.append("rect")
.attr("width", w)
.attr("height", h);
svg.append("g")
.attr("class", "x grid")
.attr("transform", "translate(0," + h + ")")
.call(d3.svg.axis().scale(x).tickSize(-h));
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + h + ")")
.call(d3.svg.axis().scale(x).tickSize(12).tickPadding(-2))
.selectAll("text")
.attr("x", 5)
.attr("dy", null)
.style("text-anchor", null);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment