1

I'm using Charts.js Doughnut chart that displays dynamic data which arrives on time intervals.
When I cancel the time intervals calls or reload the page! it looks fine:

enter image description here

When I refresh that with time intervals and go over with mouse it seems that it draw another layer on each call.

enter image description here

I already tried to draw it once and to remove and set the new data, but it still goes crazy on mouse over.

var canvas = document.getElementById('modular-doughnut');
var context = canvas.getContext('2d');
context.clearRect ( 0 , 0 , canvas.width, canvas.height );
var moduleDoughnut = new Chart(context).Doughnut(chart_data, config);

EDIT: Thanks to @Koogle I can say that the problem is in tooltips.

How to solve that?

NickF
  • 5,637
  • 12
  • 44
  • 75

1 Answers1

0

In order to use the same canvas you have to clear the reference(s) to it. Charts.js states that you must use .destroy() to clear all references to the canvas.

You read about it here: Charts.js .destroy()

I had the same issue in some dynamic charts that I made so I found it easier to just create a div around the canvas, clear the div using jquery $("#divID").empty(), and then append the new canvas.

Matt
  • 1,062
  • 1
  • 8
  • 11