[Chartjs]-Chartjs hide dataset legend v3

21👍

Configuring option like below would solve the problem in V3 version.

options: { plugins: { legend: { display: false }, } }

2👍

In Chart.js V3 you can add a filter function to options.plugins.legend.labels and evaluate either the labels or their datasetIndex values to suppress specific legends rather than ALL of them.

options: {
  plugins: {
    legend: {
      labels: {
        filter: function(legendItem, data) {
          let label = data.datasets[legendItem.datasetIndex].label || '';
          if (typeof(label) !== 'undefined') {
            if (legendItem.datasetIndex >= 3){
              return false;
            }
          }
          return label;
        }
      }
    }
  }
}

Leave a comment