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 does not render inside conditional #90

Closed
timster opened this issue Apr 14, 2017 · 5 comments
Closed

Chart does not render inside conditional #90

timster opened this issue Apr 14, 2017 · 5 comments

Comments

@timster
Copy link

timster commented Apr 14, 2017

Expected Behavior

I have two "tabs" on a page controlled by a Vue.js conditional.

Each tab has a separate chart instance with separate data. I was expecting that both charts would render. If both charts are moved outside the conditionals, they work fine.

Actual Behavior

Only the first chart seems to render. Switching to the second tab does not render the second chart - just keeps displaying the first chart.

See reproduction here: http://codepen.io/anon/pen/zwxapE?editors=1010

Environment

  • vue.js version: 2.2.6
  • vue-chart.js version: 2.6.0
  • npm version: n/a
@Pokom
Copy link

Pokom commented Apr 17, 2017

@timster
Check out my edited codepen

Check out Vue documents on conditional rendering. It's a subtle distinction, but if a div has multiple children like your case did, conditional rendering should be applied to an outer tag to ensure data gets re-rendered.

<template v-if="tab == 'one'">
    viewing chart one
    <line-chart :labels="['one', 'two', 'three']" :data="[1,2,3]"></line-chart>
  </template>
  <template v-if="tab == 'two'">
    viewing chart two
    <line-chart :labels="['four', 'five', 'six']" :data="[8,9,10]"></line-chart>
  </template>

And when you switch tabs the appropriate graph will render as you'd expect.

@timster
Copy link
Author

timster commented Apr 18, 2017

Looks like that works. Thanks for the clarification.

Is something like that worth mentioning in the vue-chartjs docs? For people like me who apparently don't remember that part of the Vue.js docs.

@apertureless
Copy link
Owner

As it is not directly related to vue-chartjs I don't see a reason to add it to the docs.

@Pokom
Copy link

Pokom commented Apr 18, 2017

I would agree with @apertureless on this one. @timster I've been caught up a lot with issues like this in both react and angular world for wrappers, and that is normally the sentiment.

One thing to note is I am actively working on improving the readability of the documentation, so I may tag you in that PR if you wouldn't mind helping out a bit.

@timster
Copy link
Author

timster commented Apr 18, 2017

I'd be glad to help if you need.

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

No branches or pull requests

3 participants