[Chartjs]-Chart.js Version 1 differences and can they be achieved in version 2?

1👍

You can replicate the v1.x functionality by extending the line chart type and setting the tooltip mode to label, like so

Chart.defaults.myLine = Chart.helpers.clone(Chart.defaults.line);
Chart.controllers.myLine = Chart.controllers.line.extend({
    updateElement: function (point) {
        var result = Chart.controllers.line.prototype.updateElement.apply(this, arguments);
        point.inRange = function (mouseX, mouseY) {
            var vm = this._view;
            // ignore the y coordinate
            return vm ? (Math.abs(mouseX - vm.x) < (vm.hitRadius + vm.radius)) : false;
        };
        return result;
    }
});

and then

    ...
    type: 'myLine',
    ...
    options: {
        tooltips: {
            mode: 'label'
        }
    }
};

Fiddle – http://jsfiddle.net/gyqmbL2q/

Leave a comment