Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

[BUG] tooltip with "index" or "nearest" mode defined can freeze chart.js if hovered as soon as it loads

Open TarekSaid opened this issue 9 years ago • 4 comments

Behaviour

This is a hard one to reproduce, as it has to be done as soon as the chart loads. The tooltip with 'index' or 'nearest' mode is incompletely loaded, which can freeze the entire chart.js. This is what happens: tooltip-error

Steps to reproduce

One way to reproduce this in jsfiddle (example code provided below):

  1. hit the "run" button;
  2. immediatly place the mouse next to where the canvas loads;
  3. as soon as it refreshes and the canvas loads, hover the mouse as fast as possible to the right.
  4. as you hover over the first dataset's bar (which shows the tooltip correctly) and then hover over the second dataset's bar, the tooltip bugs out.
  5. It might need some tries before the behaviour is reproduced.

Possible cause

If, however, you wait a few milliseconds before hovering the bars, the tooltip loads correctly. Which is why It seems to be some bug related to the tooltip mode. This happens with "index" and "nearest" mode. Maybe the tooltip code gets called before the tooltipItems array is filled. In my jsfiddle, there's a custom callback, but even when I remove it the behaviour is the same. If, however, I remove or change to tooltip mode to point, that doesn't happen.

It might be related to issue #4118, based on @etimberg's comment.

Here's the jsfiddle for the full chart.

Context

This happens rarely in the project I'm working on (in fact, so far no one has reported this error), but since it can happen and the fact that it freezes the chart makes it a serious issue. In my project, the chart is updated based on data queried after user input. The only way to make it work again is to reload the page.

Environment

  • OS: reproduced in Arch Linux 4.10.2-1-ARCH x86_64 and Windows 7 64 bit
  • Chart.js version: 2.4.0+ (tested with 2.4.0 and 2.5.0)
  • JQuery version: 2.2.4
  • Browser name and version: reproduced in Firefox 52.0 (64 bit) and Chromium 57.0.2987.133 (64-bit).

TarekSaid avatar Apr 07 '17 17:04 TarekSaid

After some further testing, it seems the problem lies with the dataset's option hoverBorderColor. Once I remove this option, the tooltip loads without a problem.

TarekSaid avatar Apr 07 '17 17:04 TarekSaid

that's weird. @TarekSaid does it go away if you set the hover mode to false and only keep the tooltip?

etimberg avatar Apr 07 '17 22:04 etimberg

@etimberg yes, also goes away if I set hover mode to point or if I remove the option hoverBorderColor.

TarekSaid avatar Apr 10 '17 14:04 TarekSaid

Can't seem to reproduce this in v2.9.3 even after reloading 20+ times. https://jsfiddle.net/ue3f4d7n/

etimberg avatar May 31 '20 23:05 etimberg