-
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
Chart not resized when changing window size in height only #3105
Comments
I played around with this. I think the problem is the way that there is no good way to know when the overall window has gotten smaller in this case. That's because the height of the page is determined by the content so when the height of the window shrinks, the browser simply makes the page scrollable to the user. To the content, however, there is no change which is why our resize listener never fires. When the width changes, the content is changed and our resize listener fires trigger the full update to the real size. |
I agree with @etimberg that there's no easy way of knowing height changes so your best bet is to set up an event listener on the window to manually call I recently did it this way and it works like a charm. Here's your fiddle with it. https://jsfiddle.net/wbjkgmta/
Note this implementation resizes twice so could be optimized to only execute if width isn't changing. |
I understand, thanks for the feedback! |
@JBildstein in your example, I think the issue is that the hidden iframe (used to detect size changes) doesn't fit vertically. Can you try to add this to your stylesheet: .chartjs-hidden-iframe {
height: 100% !important;
} However, I'm not sure about side effects for having the iframe with |
I updated the fiddle to add the css rule above and remove the resize listener. It works pretty well so was thinking that we should change the height of the iframe for |
@simonbrunel I can't remember why it was 0. We should be able to set to 100% without issues but we should unit test it. |
Ensure that the hidden iframe is stretched vertically in order to detect height changes. Remove the classlist check/call since it was incorrectly spelled (should be classList), but also useless since the iframe has just been generated. Also remove the callback check: addResizeListener should never be called w/o a valid callback.
Ensure that the hidden iframe is stretched vertically in order to detect height changes. Remove the classlist check/call since it was incorrectly spelled (should be classList), but also useless since the iframe has just been generated. Also remove the callback check: addResizeListener should never be called w/o a valid callback.
Ensure that the hidden iframe is stretched vertically in order to detect height changes. Remove the classlist check/call since it was incorrectly spelled (should be classList), but also useless since the iframe has just been generated. Also remove the callback check: addResizeListener should never be called w/o a valid callback.
@simonbrunel sorry for taking so long (different project came in between). I tried it and it works perfectly. |
Ensure that the hidden iframe is stretched vertically in order to detect height changes. Remove the classlist check/call since it was incorrectly spelled (should be classList), but also useless since the iframe has just been generated. Also remove the callback check: addResizeListener should never be called w/o a valid callback.
Fixed by PR #3326, will be released in 2.4 :) |
Ensure that the hidden iframe is stretched vertically in order to detect height changes. Remove the classlist check/call since it was incorrectly spelled (should be classList), but also useless since the iframe has just been generated. Also remove the callback check: addResizeListener should never be called w/o a valid callback.
Hi, is there any way to maintain aspect ratio and make chart vertically responsive at the same time? |
since js is manipulating the width and height of the canvas you need to define 100 % width and height in your custom css to prevent manipulation |
As per title, if I have a responsive chart (with maintainAspectRatio: false) the chart is not resized if I change the window size in height only. As soon as I change the window width it adjust itself correctly.
In this example it seems to resize correctly if the window size is getting bigger but not when it's getting smaller (or only rarely or sometimes when changing very fast).
In my real app it doesn't resize in either way but I can't reproduce it into a small example.
I couldn't get this behavior on jsfiddle or codepen but here is an example html page:
The text was updated successfully, but these errors were encountered: