FVANCOP / ChartNew.js

MIT License
420 stars 143 forks source link

How can I check if there is a chart drawn successfully in canvas #453

Closed VampireDaniel closed 7 years ago

VampireDaniel commented 7 years ago

How can I check if there is a chart drawn successfully in canvas. Is there any function?

FVANCOP commented 7 years ago

I will answer to your question with another question : what does it mean that a chart is successfully drawn ? It is not because it goes up to the end of the program that the chart is well drawn...

By the way, currently nothing can be used to check if a chart is drawn. I will add something that could be checked afterwards; For instance, the number of bars, points, pieces of cake drawn in the chart; If this value is zero, it means that nothing has been drawn.

This will be available at the end of the month (currently busy to rewrite the setMeasure function and it is not easy...).

Regards, François

VampireDaniel commented 7 years ago

What a chart is successfully drawn means I want to know if the chart is completely drawn, likes the function .is(":animated") checking the element is in a state of animation or not. (I tried this function, but not work. May be could add stopDrawChart() function as well).

Now, I use ChartNewId checking if the chart exists. And, I have more than 5 charts been switched by clicking buttons using updateChart() function, and if switch speed is faster than the drawn speed of chart, some bugs occur. Such as, if I switch to a new chart when the old chart is drawing, the new chart will not appear instead of old chart without X-Axis and Y-Axis labels.

Best Regards.

FVANCOP commented 7 years ago

OK - I now understand what you mean.

There is a "not documented" variable that can be used.

  var Cht1 = new Chart(document.getElementById("canvas_1").getContext("2d")).Line(mydata1,setopts1);
  (...)
  if (Cht1.firstPass ==9) {
       // firstPass == 9 <=> chart is completely drawn;
   }
VampireDaniel commented 7 years ago

I'll try this, thank you very much

FVANCOP commented 7 years ago

See last changes.

https://github.com/FVANCOP/ChartNew.js/wiki/075_Return_value