Chartjs-Remove tooltip if has no label

1๐Ÿ‘

โœ…

Add typeof to check if label is undefined, so hide() or destroy() if need it.

tooltips: {
  callbacks: {
    label: function(tooltipItem, data) {
      var label = data.labels[tooltipItem.index];
        if(typeof label !== 'undefined') {
          return label;
        } else {
          label.destroy();
        }
      }
    }
  }

1๐Ÿ‘

First use typeof label != "undefined" to see if its undefined or not.

Second use optionsSistema.defaults.global.tooltips.enabled = false; this will remove the label.

Here is a demo of it.

0๐Ÿ‘

tooltips: {
    callbacks: {
      label: function(tooltipItem, data) {
        var label = data.labels[tooltipItem.index];
        if(label !== undefined){//use undefined instead 'undefined'
          return label;
        }else{
          return label.destroy()
         }
      }
    }
  }

0๐Ÿ‘

There is no other option than to use custom tooltip using custom property of tooltip object. Refer custom tooltips

Leave a comment