[Chartjs]-Chart.js chart onclick disables legend onclick

3👍

Try like that:

var legendClick = Chart.defaults.global.legend.onClick;
Chart.defaults.global.legend.onClick = function(e, legendItem) {
    console.log(legendItem);
    legendClick.call(this, e, legendItem);
};

legendItem contains the index of the bar that was clicked.

legendClick.call(this, e, legendItem) performs the default click handler.

Leave a comment