Chartjs-Custom legend hide() does not remove data labels

1👍

It seems that the onClick function is working properly.

I have tried the attached code, leveraging on toggleDataVisibility API, and it’s working as requested (codepen: https://codepen.io/stockinail/pen/abKNJqJ):

function chartOnClick(evt) {
    let chart = evt.chart
    const points = chart.getElementsAtEventForMode(evt, 'nearest', {}, true);
    
    if (points.length) {
       const firstPoint = points[0];
        chart.toggleDataVisibility(firstPoint.index);
        chart.update();
    }
}

Leave a comment