Chartjs-How to manage line, scatter plot by same label?

0👍

setChartPlugin({
    title: {
      display: false
    },
    legend: {
      labels: {
        filter: function(legendItem, chartData) {
          if (legendItem.datasetIndex === 0) {
            return true;
          }
          return false;
        }
      },
      onClick: function(e, legendItem, legend){
         const index = legendItem.datasetIndex;
         const ci = legend.chart;
         if (ci.isDatasetVisible(index)) {
           ci.hide(index);
           ci.hide(index+1);
           legendItem.hidden = true;
         } else {
           ci.show(index);
           ci.show(index+1);
           legendItem.hidden = false;
         }
      }
    },
  }); 

add this code block in chart plugin. It works.

Leave a comment