-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Method of destroying morris instance? #569
Comments
I just noticed that the reason for the crashes appear to be the following (awesome) option: resize: true After a tab switch, and upon window resize (or inspect element, which sort of resizes the window) - that's when everything crashes. I've temporarily switched off resize and things work smoothly. However, unresponsive charts are pretty useless 2015. Is there anyway to unbind the resize: true setting? |
Solved: $(window).off('resize');
window.morrisObj = NaN; Still interested in official ways of killing responsive morris instances. Anyone? |
Looking at the code, there doesn't appear to be any other way to do this currently If the resize handler wrapper ( morris.js/lib/morris.grid.coffee Line 84 in 4ccdd76
However, that is not the case. handler wrapper is anonymous and it would be hack solution anyway. I'm not sure if this is the only case, when morris binds globally to an event - anyway as you showed above, there is need for clean destroy method. I think issue is still valid and it's best to reopen it. |
Thanks for your response, leriel! I've now reopened the issue. Let's hope for a less hacky solution! |
window.morrisObj.destroy() would be great... especially when using morris with e.g. modals, just to clean up after closing them. Even setting it to NaN the event handlers are still listening |
I got the same issue when I was trying to use Morris charts in a singple-page setup. After removing the chart DOMs, we get some javascript errors owing to the One possible way to fix this is to use jQuery's event namespaces, i.e. calling |
Agree, namespace event handlers can easily solve a lot of conflicts
|
I solved my issue by simply calling |
I solved my problem adding this to morris.js after function Grid(options), and calling it properly before delete the object.
|
lbolanos cheers - just what I needed. |
I little change above solution to clear also svg element (if we don't do it on reset chart, the new and old chart and svg elements will be still visible...):
|
@lbolanos Could you please tell me where should I call destroy function in morris.js? |
Another integration to
So the method is exposed to all chart types; for example:
So |
When I used the " $('#chart').empty(); " solution it broke the hover labels Using the " destroy() " method preserved the hover functionality I had to attach the destroy() to the Grid inside the Morris Morris.Grid.prototype.destroy = function () { ... }; |
@ajoslin103 You can check my fork, it includes a built-in destroy function |
This is my first post ever at Github!
I'd really like to use Morris.js for a project of mine, however I'm stuck at one critical point.
My web app does not use traditional page loads, but instead uses ajax to empty the content of the main container, and fill it with the content of the page that should be loaded. When that's done it executes a js function for that specific page, which does different things for different pages.
On one page I'm using a morris graph. (so far just a test graph) The page to be loaded looks like this:
The function that is run on page load is the following:
The ajax call that does all the magic looks like this:
As you can see I'm trying to kill/unload any morrisObj that might exist with the following line in my ajax code:
This method does not work. After a couple of loads back and forth, morris.js is working so hard that it stops responding to the point where I have to reboot my computer.
I've really tried to google my way out of this one, but I can't seem to find anyway of killing a morris instance.
Tl;dr: How do I destroy a morris instance properly?
The text was updated successfully, but these errors were encountered: