Reputation: 3923
The graph doesn't draw and the console throws this: Uncaught Error: Invalid dimensions for plot, width = 1350, height = 0
is the error.
I tried recreating the error on a JSFiddle but was unable to do so, however here is what it should resemble: JSFiddle
Some notes on this error:
Sometimes on the first x page loads, the graph will be drawn, and then it will cease after throwing up that error.
Here is the full error:
Uncaught Error: Invalid dimensions for plot, width = 1350, height = 0 jquery.flot.js:119
Canvas.resize jquery.flot.js:119
Canvas jquery.flot.js:98
setupCanvases jquery.flot.js:1261
Plot jquery.flot.js:674
$.plot jquery.flot.js:3039
visc_graph active-scripts.js:45
(anonymous function) active-scripts.js:346
k jquery.min.js:2
l.fireWith jquery.min.js:2
p.extend.ready jquery.min.js:2
D jquery.min.js:2
And it seems to get thrown from here in the jquery.flot source:
Canvas.prototype.resize = function(width, height) {
if (width <= 0 || height <= 0) {
throw new Error("Invalid dimensions for plot, width = " + width + ", height = " + height);
Uncaught Error: Invalid dimensions for plot, width = 1350, height = 0
}
EDIT:More information:
Unlike the JSFiddle linked above, I am plotting multiple graphs using that function - something like this, however, when I'd created separate functions for each placeholder
div, this did not occur.
Calling the graphing function from the console i.e. visc_graph(2,3,'#placeholder');
seems to work fine :(
I've been struggling with this for a while as I have no way of diagnosing what the actual cause of this is. Any input as to how I could approach solving this would be immensely appreciated.
UPDATE:
Upvotes: 2
Views: 2519
Reputation: 38189
That error arises when Flot can't determine the size of the placeholder div. This can happen in several ways, but generally it means that you called $.plot
before the placeholder was in the DOM.
This can happen, as @Mark suggested, if you're calling $.plot
before the document is ready, but it can also happen in other ways. Are your plots held in tabs, accordions, dialog boxes, or any other widget whose contents are hidden on page load? If so, that's likely implemented by leaving the content div out of the DOM, which means that the plot placeholder is also outside of the DOM and can't be measured.
There's really no other reason why this error would arise, so if you still don't see the problem you'll need to post more of your code - in particular the DOM portion - so we can understand what's happening.
Upvotes: 5
Reputation: 33
I had same issue last night, what I did to fix this issue was to set the placeholder div size using css something like this:
<style type="text/css">
#placeholder{
width:100%;
height:200px;
}
</style>
<div id="content" class="demo-container">
<div id="placeholder" class="demo-placeholder"></div>
</div>
after setting div size it started working.
I hope this helps you.
Upvotes: 2