I have a datetime series along the x axis of a chart in Chart.js but have changed the position of the tick / labels to be between the bars according to the method here:
Chart.js : How I change the x axes ticks labels alignment in any sizes?
This resulted in the datetimes moving to the right of the bar they related to, whereas I needed them on the left. So I changed the return calculation to subtract the amount instead of add:
var TimeCenterScale = Chart.scaleService.getScaleConstructor('time').extend({
getPixelForTick: function(index) {
var ticks = this.getTicks();
if (index < 0 || index >= ticks.length) {
return null;
}
// Get the pixel value for the current tick.
var px = this.getPixelForOffset(ticks[index].value);
// Get the next tick's pixel value.
var nextPx = this.right;
var nextTick = ticks[index + 1];
if (nextTick) {
nextPx = this.getPixelForOffset(nextTick.value);
}
// Align the labels in the middle of the current and next tick.
return px - (nextPx - px) / 2;
},
});
This mostly works except for the last column. How can I align this last column correctly?