Chart.js: Enable tooltip by click

Created on 26 Jul 2016  路  7Comments  路  Source: chartjs/Chart.js

Hello everyone,

I would like to display tooltip only by user click. The aim is to replace the actual hover event by the click event on the same chart element.
I didn't find any answer on this topic for the second chart.js version.

Thank's for your help :+1:

Guillaume

Most helpful comment

I found a solution. We have to change the global event array :
Chart.defaults.global.events = ["click"]

All 7 comments

I found a solution. We have to change the global event array :
Chart.defaults.global.events = ["click"]

Thanks for posting the solution @koehrlenguillaume

tooltip doesn't hide when you click outside the chart

@marloningal Did you find a solution for outside click?

@frabnt not yet

@marloningal

The angular way:

@HostListener('document:click', ['$event'])
  private _hideTooltip($event: MouseEvent) {
    const clickedInside = this._elementRef.nativeElement.contains($event.target);
    if (!clickedInside) {
      const tooltip = this._chart.tooltip; // this._chart is a reference to the chart instance
      tooltip._active = [];
      tooltip.update(true);
      this._chart.update();
    }
  }

I found a solution. We have to change the global event array :
Chart.defaults.global.events = ["click"]

Thank you for solve this problem @koehrlenguillaume

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Woogles picture Woogles  路  3Comments

joebirkin picture joebirkin  路  3Comments

benmccann picture benmccann  路  3Comments

nickgoodliff picture nickgoodliff  路  3Comments

gabrieldesouza picture gabrieldesouza  路  3Comments