I'm using D3.js to create some simple bar graphs, and was using the d3.time.scale()
for the x-axis.
But, I stumbled upon one irregularity (or so it seems to me, although of course, I'm wrong :P)
When I generate the scale with ticks at monthly intervals, the difference between the ticks is not equal.
scaleX = d3.time.scale()
.range([0, 1000])
.domain([new Date('2014-01'), new Date('2014-12')])
scaleX(new Date("2014-01")) // 0
scaleX(new Date("2014-02")) // 9.28... (diff ~ 9.3)
scaleX(new Date("2014-03")) // 17.66... (diff ~ 8.4)
scaleX(new Date("2014-04")) // 26.94... (diff ~ 9.3)
This causes the bars in the graph to be unevenly spaced, leading to ugly graphs...
What's the correct way to evenly space out the bars with months as ticks? I realize that there is the possibility to use an ordinal
scale to do this, but it doesn't feel right, also the ordinal scale would not draw ticks for months for which I don't have any data.
Edit: a little clarification on the question: Since SO is for programmers, I only asked the "correct way" to make the ticks evenly spaced out. But what I really want to ask is this:
Is is acceptable to display time-charts with ticks of unequal length?