Is there a recommended way to clear a jQuery Flot graph? I couldn't find anything the in the API reference.
JQuery Flot: clear graph
By "clear" do you mean "nuke the entire graph," or just clear the data?
To nuke the entire graph: $('#canvas_id').empty();
To clear the data, just call the usual $.plot(placeholder, data, options);
where data is empty.
is there any significance with respect to nuking...? –
Marrano
What is the right way to make sure all event handlers are cleaned up? –
Seesaw
@Seesaw any sane browser (so, exclude old versions of IE) should take care of this for you. Are you seeing evidence to the contrary? –
Corpora
This creates generates an error when attempting with the pie plugin. –
Raybin
@JoshBuchea for what it's worth, this answer is well over eight years old, which is pretty much an eternity in Javascript years. –
Corpora
@MattBall an eternity indeed. Believe it or not I'm working at a startup that uses Flot charts in production today, so the information is still relevant to some! –
Raybin
in my case just clearing container won't help, some flot bindings stil working.
var plot = $.plot(placeholder, data, options);
// some other code
//to completely remove flot chart call
plot.destroy(); // remove graph and all bindings
to clear only graph use Matt Ball ansver.
Thanks for pointing me to destroy! Also helpful to note that destroy will internally call shutdown and remove any registered event handlers. –
Raybin
© 2022 - 2024 — McMap. All rights reserved.