axes callbacks used to get zero at center

I have been trying to use axes call backs to do the following:

scales: {
    callbacks: {
        afterDataLimits: function (axis) {
            console.log("callback for..", axis);
                if (axis.id == "right-y-axis") {
                    var absMax = Math.max(Math.abs(axis.ticks.min), Math.abs(axis.ticks.max));
                    axis.ticks.min = -absMax;
                    axis.ticks.max = absMax;
                }
            }
        },

After the datalimits had been determined I had hoped to then reset them to my own min and max values to ensure zero was always at centre and then tick scaling could be executed in the next part of the the process so this keeps much of chart.js dynamical scaling.

But it doesn’t work, in fact the callback never even seems to be registered, and I have tried other callback without success.

A mock up of the problem is viewable at:
https://codepen.io/attack68/pen/BwbYQK

Author: Fantashit

1 thought on “axes callbacks used to get zero at center

  1. I think the Axes docs are confusing in this situation. It seems like the config would be:

    scales: {
        xAxes: [{
            id: 'x-axis-1',
            callbacks: {
                afterDataLimits: function (axis) {
                },
            }
        }]
    }

    but it actually should be:

    scales: {
        xAxes: [{
            id: 'x-axis-1',
            afterDataLimits: function (axis) {
            },
        }]
    }

    See:

    helpers.callback(this.options.afterDataLimits, [this]);

Comments are closed.