Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
129
rated 0 times [  135] [ 6]  / answers: 1 / hits: 21877  / 14 Years ago, thu, may 13, 2010, 12:00:00

I'm using the Flot graphing library jQuery plugin and I haven't found a good way to handle resizing the graph when it's containing <div> changes size (for example, due to window resizing). When handling the onresize event, I've made sure that the width and height of the containing <div>are updated to the correct size and then tried calling both setupGrid and draw on the plot object but with no effect. I've had some success with the approach of just removing and readding the containing <div> and replotting the graph in it. However, this seems to be prone to getting stuck in infinite resize event loops if I have to add other <div> elements to the document at the same time (like for tooltips for the graph) as I'm guessing those can trigger resize events as well? Is there a good way to handle it that I'm missing?



(I'm also using ExplorerCanvas for IE in order to be able to use Flot, if that might have anything to do with it. I haven't really tried in any other browsers yet)


More From » jquery

 Answers
7

I have found just binding to the resize event on the window and calling plot works really well. For example I have my data and options stored in variables on the page. Then I setup this on $(document).ready():




$(window).resize(function() {$.plot($('#graph_div'), data, opts);});



[#96792] Tuesday, May 11, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
acaciac

Total Points: 317
Total Questions: 117
Total Answers: 128

Location: France
Member since Thu, Oct 27, 2022
2 Years ago
;