Skip to content
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

[BUG] Display none with maintainAspectRatio: false causes squished chart #4659

Closed
nelsyeung opened this issue Aug 15, 2017 · 4 comments · Fixed by #8632
Closed

[BUG] Display none with maintainAspectRatio: false causes squished chart #4659

nelsyeung opened this issue Aug 15, 2017 · 4 comments · Fixed by #8632

Comments

@nelsyeung
Copy link

Expected Behavior

When the canvas container has style="display: none;" then later on set to block using JS, used with the chart option maintainAspectRatio: false, the chart should be the same size as without the complications with display: none.

Current Behavior

When the canvas container has style="display: none;" then later on set to block using JS, used with the chart option maintainAspectRatio: false, the height of the chart is squished to around 20px or in some cases 0px.

Steps to Reproduce (for bugs)

fiddle

  1. Press "Toggle Display"
  2. You should see that the chart is squished (very low height).
  3. Remove the style="display: none; and re-run the fiddle.
  4. You should see that the chart is the correct size.

I expect both to have the same size.

Environment

  • Chart.js version: 2.6.0
  • Browser name and version: Firefox 54.0.1
@etimberg
Copy link
Member

@nelsyeung I would use CSS height and width which seems to work https://jsfiddle.net/oacLn7ku/1/

I think the bug, if any, here is that a resize to 0x0 works. There is nothing around the chart container to give it height so the initial default height of 150 isn't retained.

CC @simonbrunel thoughts?

@naheller
Copy link

I'm also affected by this issue. In my case, I'd like the chart to show/hide based on screen width.

However, loading into a page width where the chart is hidden and then expanding the window does not cause the chart to appear, as is desired.

@simonbrunel
Copy link
Member

@naheller what version? what options? Did you try to set an explicit height on your parent container?

I think 2.7.x brought everything needed to implement these use cases.

Can you share a jsfiddle that reproduces your issue?

@etimberg
Copy link
Member

etimberg commented Oct 9, 2020

Original issue still reproduces in v3.0.0-beta.3 https://jsfiddle.net/5naxr3v8/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants