Search code examples
javascriptchartstooltipchart.js

How to show tooltip only when data available in chart js?


How to show tooltip only when data available in chart js?

enter image description here

callbacks: {
  title: (item, data) => this.projectNumberArray[item[0].index],
  label: (item, data) => this.projectNameArray[item.index]
},

And I want disable tooltip, when I don't have needed data.


Solution

  • I have been faced same problem several days ago. I checked documentation and github both but i couldn't find the solution for disabling tooltip when data is not available.

    Then i found a solution.

    Then i checkced data on runtime and set a variable. When i draw chart then i check variable which i have been set on runtime and disable the tooltip accordingly.

    tooltips: {
          enabled: false
    

    }

    You can use above piece of code for disabling tooltip while drawing chart on canvas.