-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tooltip causing reverting to old chart when rendering different charts in same canvas #920
Comments
I am also having the same issue, when I use the same canvas to draw chart second time, then on hover it shows the previous chart. How to solve this? |
My solution was to just create different canvases to use with the different refreshes - it is a hack, but it fixed the issue. I had 5 different charts, so I made 5 different canvases, and did the hide/show toggle kind of thing. |
Try to create a global chart instance and before update it, use .destroy() to clear the old chart instances. This is happening because you're creating new instances over the same canvas and then the old points in the chat call their tooltip function what causes the old charts to show up. I did this in my chart to solve this problem: ...
if($scope.myLineChart !== undefined || $scope.myLineChart !== null){
$scope.myLineChart.destroy();
}
... |
Thank you @JoabMendes , it works :) |
@brenthamby it will make your view very heavy and you got more work to do. Try to see the solution I gave here 😄 |
Thanks a lot @JoabMendes! Man, you saved my week! 🎉 Honesly, I'm almost give up. I've had this issue for awhile but I couldn't figure it out why it was happening 😔 Regards! |
You are welcome @jobsamuel! 😃 |
Thx solved my problem!!! |
I have just experienced the same issue. Debugging it looked really scary, but your solution worked like a charm. Thanks for saving me a lot of time! |
@JoabMendes, It doesn't work for me, but I found the solution: $timeout(function() {
...
}, 200); I think it's because ChartJS can't finish chart.clear() to clear the canvas, so old data appears. |
It depends on you implementation @ifokeev , if you have any way to make the chart a global instance you can destroy the previous rendering before create a new one, in the same canvas. |
I am also having the same issue. |
@JoabMendes, can you please explain a bit more on how to create a global chart instance? Tried a couple of things but did not work. |
@jeetu3indra @zurez However, if you are using pure javascript as I think you are: If you use window to create a global object, I believe you don't even need to use the destroy like I did, in order to avoid the overlap. Since the replace of the object deletes the old version in the DOM. ...
if(window.myLineChart !== undefined || window.myLineChart !== null){
window.myLineChart.destroy();
}
... I hope it can help you. 😄 |
@JoabMendes any chance you'd be able to post up a complete JSBin example with the fix you described. I can't seem to get mine working properly. Would greatly appreciate it. |
@JoabMendes : Thanks , but there is a problem with destroying chart manually. If using the same canvas, the chart is not recreated automatically if new data is parsed after manual chart destruction. |
Also the timeout fix worked for me . thanks @ifokeev 👍 |
Thanks @JoabMendes. I created global object like below on top. var chartObj; Then just before initializing the chart i destroyed as follows. if (chartObj != undefined || chartObj != null) {
chartObj.destroy();
} |
Appreciate it @JoabMendes . Looking forward to it ;) |
Closing since the correct fix is to use |
@JoabMendes thank you very much, works great👍 |
It renders a really low resolution chart after I destroy the data with chart.destroy() |
Hope this might help you https://stackoverflow.com/a/48508231/4337125 |
Before creating new instance we need to run destroy() on old instance if it is exists to avoid **Hovering over line chart shows old chart data** bug problem, which is described here: chartjs/Chart.js#920 jtblin/angular-chart.js#187 ### Fix or Enhancement? Fix - [x] All tests passed ### Environment - OS: Windows 7 - NPM Version: 6.1.0
Before creating new instance we need to run destroy() on old instance if it is exists to avoid **Hovering over line chart shows old chart data** bug problem, which is described here: chartjs/Chart.js#920 jtblin/angular-chart.js#187 ### Fix or Enhancement? Fix - [x] All tests passed ### Environment - OS: Windows 7 - NPM Version: 6.1.0
Hi, |
Angularjs |
Before creating new instance we need to run destroy() on old instance if it is exists to avoid **Hovering over line chart shows old chart data** bug problem, which is described here: chartjs/Chart.js#920 jtblin/angular-chart.js#187 ### Fix or Enhancement? Fix - [x] All tests passed ### Environment - OS: Windows 7 - NPM Version: 6.1.0
Before creating new instance we need to run destroy() on old instance if it is exists to avoid **Hovering over line chart shows old chart data** bug problem, which is described here: chartjs/Chart.js#920 jtblin/angular-chart.js#187 ### Fix or Enhancement? Fix - [x] All tests passed ### Environment - OS: Windows 7 - NPM Version: 6.1.0
If I render one bar chart with certain data then render a different chart with (new Bar Chart Obj), but use the same canvas, when I mouse over the new chart to show the tooltip - it will revert back to the old chart!!
I even tried to call clear on the Obj reference and also tried clearing the canvas manually - no luck.
Insights?
The text was updated successfully, but these errors were encountered: