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

Chart doesn't load in bootstrap tab #157

Closed
mwei0210 opened this issue Jul 27, 2017 · 9 comments
Closed

Chart doesn't load in bootstrap tab #157

mwei0210 opened this issue Jul 27, 2017 · 9 comments

Comments

@mwei0210
Copy link

mwei0210 commented Jul 27, 2017

Expected Behavior

Charts in both active and inactive tab to load

Actual Behavior

Only chart in active tab load but not the inactive tab

@apertureless
Copy link
Owner

Please provide a codepen or jsfiddle for reproduction.

@mwei0210
Copy link
Author

See if this is sufficed,

<div class="tab-pane active" id="tab-1">
    <chart></chart>
</div>
<div class="tab-pane" id="tab-2">
    <chart></chart>
</div>

Chart in the first tab-1 works but when i switch to tab-2, the chart doesn't show at all. Thanks

@apertureless
Copy link
Owner

Hey, I need a working example to debug it.

Are you using a vue-bootstrap lib? Or pure bootstrap?

@mwei0210
Copy link
Author

Its on pure bootstrap. May need sometime setting the reproduction up..

@apertureless
Copy link
Owner

You can easy load it in codepen just add the bootstrap files the vue-chartjs cdn and you can start.
Check out the https://codepen.io/apertureless/pen/vxWbqB?editors=1010

@mwei0210
Copy link
Author

mwei0210 commented Jul 27, 2017

Try navigating between tabs, only tab 1 is loaded and other tabs won't.
https://codepen.io/mwei0210/pen/ayvoyO
Thanks

@apertureless
Copy link
Owner

Thanks for this!

Well, the problem is, how chartjs works if you pass responsive: true.
What responsive: true does, it so set the width and height of the chart, based on the outer div.

In your example it's the tab-pane . However, because of the tabs, only the active tab has a height and width, as the other hidden tabs are set to display: none so their height and width is 0.

But the vue chart component gets loaded and chartjs sets the chart height and width to 0.
If you now click on the second tab, the class sets it to display: block However the chart can't detect that change.

There are two possible solutions for you.

  1. You set responsive: false and may set an fix width and height. This way you will see the charts if you change the tabs.

  2. You use a vue based tabbar. This whay you could add a v-if to the chart and only mount it if the tab is open, so chart.js can detect the width and height of the outer div.

@mwei0210
Copy link
Author

Got it! Thanks!

@fmmattioni
Copy link

For anyone that is looking for a solution now, you can simply add lazy to <b-tab> and it works.

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

No branches or pull requests

3 participants