-
-
Notifications
You must be signed in to change notification settings - Fork 838
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 is not rendered when maintainAspectRatio is set to false and chart container is hidden #235
Comments
Can you provide a codepen for reproduction? |
closed due to inactivity |
Hi, I have the same problem. I'm using bootstrap-vue and the tabs component and here is a codepen with the problem https://codepen.io/goranmitev/pen/NXXEpy When you put a chart in an inactive tab, the chart is not rendered if maintainAspectRatio: false |
Well thats a common thing with chart.js. Thats why you can't see anything. Chart.js is grabbing the height and width and applying it to the canvas. Because
So I guess setting the tab to |
Have the same problem with vuetify tabs, though in my case it is not displaying the charts because the height gets set to 0. Setting Interestingly, if I switch from having |
Has anyone been able to find a workaround for this? I hit it a few months ago in Chrome for an application I was co-developing and found this thread to be useful; when I realised that it was the canvas height that was being set to zero I could set the height after instantiating the chart and then the chart rendered fine. Unfortunately this fix doesn't work in Firefox. I've attached a pseudo-code version of the widget to show the structure of the file in case this helps to identify the problem. Changing the chart option 'maintainAspectRatio' to true means the chart is rendered, but at the wrong aspect ratio. |
Well, there is no real workaround. Like explained, if the canvas has a You could maybe try to add a MutationObserver to the element and check if the Otherwise don't use |
resize add in settimeout
i think |
Just Defining parent height it will work like charm.
Now show/hide renderChart will work. |
Another solution is to adapt the radius so it can fit the screensize so you don't need maintainAspectRatio = true that is causing the problem, you have an event called "onresize". For my case, on web screen radius = 300, on mobile screen radius = 150 for example. |
Hi,
First of all, thanks for creating this package as vue wrapper for chartjs. I have a use case where my chart is hidden initially then when the user will click the button, the chart will show.
Before I added the option
maintainAspectRatio: false
, everything works fine. The chart will be rendered even it is being rendered in a hidden div. But once I added the option mentioned above, only charts that are visible is rendered. The hidden charts are not rendered.Expected Behavior
Chart should still render in a hidden div with
maintainAspectRatio: false
Actual Behavior
Chart is not rendered in a hidden div with
maintainAspectRatio: false
Environment
UPDATE
I found out that the bug when the container is hidden is the canvas height is
0
. It seems that the height props was not properly propagated if container is hidden upon rendering.The text was updated successfully, but these errors were encountered: