block by mbostock 1399097

Left-Aligned Ticks

Full Screen

index.html

<!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>