How to disable a tooltip for a specific dataset in ChartJS

后端 未结 4 1896
忘了有多久
忘了有多久 2020-12-10 12:23

I displaying a chart where two types are included. Now I want to hide the toolbar for one dataset. I saw some discussion like this on GitHub, but this doesn\'t bring me furt

4条回答
  •  伪装坚强ぢ
    2020-12-10 12:38

    You can use this filter:

     tooltips: {
            filter: function (tooltipItem, data) {
                 var datasetLabel = data.datasets[tooltipItem.datasetIndex];
                 var datapointLabel = data.labels[tooltipItem.index];
                 var datapointValue = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
    
                  //you can also use tooltipItem.xlabel or ylabel to get datapoint label and value but here it depends on you chart orientation                
    
                  if (datasetLabel=="production" && datapointLabel=="red" && datapointValue<30) {
                       return false;
                  } else {
                       return true;
                  }
            }
     }
    

提交回复
热议问题