This is an old thread, but I ran in to this problem recently and this post was all I found on Google.
If for visual reasons you don't want to rotate the ticks, I found another solution.
After creating the x axis I saved all of the '.tick' classed elements back to an array:
var dateTicks = svg.append('g')
.attr('class', 'x axis')
.attr('transform', 'translate(0, ' + height + ')')
.call(xAxis)
.selectAll('.tick');
I then iterated through the collection of ticks and used the .getBoundingRect() method to detect whether the tick was colliding with its neighbors:
for (var j = 0; j < dateTicks[0].length; j++) {
var c = dateTicks[0][j],
n = dateTicks[0][j+1];
if (!c || !n || !c.getBoundingClientRect || !n.getBoundingClientRect)
continue;
while (c.getBoundingClientRect().right > n.getBoundingClientRect().left) {
d3.select(n).remove();
j++;
n = dateTicks[0][j+1];
if (!n)
break;
}
}
Still looking for a cleaner way to do this that is more "d3", but just wanted to share this solution if anyone else is going crazy with the ticks overlapping!