Home Forums Report Bugs When summer time ends Charts axis labelFormatter “skips” an entire hour Reply To: When summer time ends Charts axis labelFormatter “skips” an entire hour

#36046

Indranil,

I have hacked my way to get a working example using our customer’s data. I used the minified library for the old version they have in their website so please excuse me if the variable names don’t match the current ones in the most recent version.

Our starting point will be the function “E.prototype.createLabels”, which controls how the labels will be created. I will modify this block a bit (I have formatted it so I could know what the “for” was doing):

if ("axisX" === this.type && "dateTime" === this.chart.plotInfo.axisXValueType)
{
    for (
        this.intervalStartPosition = this.getLabelStartPoint(new Date(this.viewportMinimum), this.intervalType, this.interval),
        d = taNew(this.viewportMaximum, this.interval, this.intervalType),
        b = this.viewportMinimum;
        
        b < d;

        b = taNew(b, this.interval, this.intervalType)
    )
    {
        a = b, a = this.labelFormatter ? this.labelFormatter({
            chart: this.chart._publicChartReference,
            axis: this._options,
            value: b,
            label: this.labels[b] ? this.labels[b] : null
        }) : "axisX" === this.type && this.labels[a] ? this.labels[a] : ra(b, this.valueFormatString, this.chart._cultureInfo), a = new M(this.ctx, {
            x: 0,
            y: 0,
            maxWidth: e,
            maxHeight: g,
            angle: this.labelAngle,
            text: this.prefix + a + this.suffix,
            horizontalAlign: "left",
            fontSize: this.labelFontSize,
            fontFamily: this.labelFontFamily,
            fontWeight: this.labelFontWeight,
            fontColor: this.labelFontColor,
            fontStyle: this.labelFontStyle,
            textBaseline: "middle"
        }), this._labels.push({
            position: b,
            textBlock: a,
            effectiveHeight: null
        });
    }
}

I am also calling a new function, “taNew”, which is not really optimal but will help us do the trick:

function taNew(a, c, b){
    if ("millisecond" === b) return a + 1 * c;
    if ("second" === b) return a + 1 * 1000 * c;
    if ("minute" === b) return a + 1 * 1000 * 60 * c;
    if ("hour" === b) return a + 1 * 1000 * 60 * 60 * c;
    if ("day" === b) return a + 1 * 1000 * 60 * 60 * 24 * c;
    if ("week" === b) return a + 1 * 1000 * 60 * 60 * 24 * 7 * c;
    if ("month" === b) return a + 1 * 1000 * 60 * 60 * 24 * 30 * c;
    if ("year" === b) return a + 1 * 1000 * 60 * 60 * 24 * 365 * c;
}

Please note that I am not creating Date objects in the process because I will leave this task to my own code when I create the chart. With these changes, the result is this:

The chart with the changes applied

We can see that axisX now has all the marks from 11PM to 4AM (I guess it shifts one second because my code is not perfect, but it is a real progress). Since I never use “new Date()” in the library the variables are integers representing timestamps and I leave the task to transform them into readable times to a custom function in labelFormatter. Thus, the axis is not “broken” anymore.

Hope this helps you debugging.

Regards.