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 display freaks out when using collection.find().observeChanges to update chart #3

Open
ecofriend opened this issue Aug 8, 2015 · 6 comments

Comments

@ecofriend
Copy link

Here is a link to the partial, relevant code: http://jsbin.com/dutiqadovu/edit?html,js,output

If I use the Questions.find().observeChanges method, the chart becomes jumpy when I hover over the segments. If I leave this method out, then the chart behaves normally.

Please let me know if I need to provide additional information.

@ecofriend
Copy link
Author

I am using observerChanges because that is the only way I could figure out to update the chart reactively. If there is a better way, that doesn't also redraw the chart, that would be great.

@froatsnook
Copy link

In your code, showAgeGroups is called every time something in the collection changes. This means you're creating a new Chart on the same canvas over and over without cleaning up the old canvas. The behavior is much better if you call destroy before creating the new chart. You're also creating a new Chart twice for some reason.

var lastChart;
function showAgeGroups() {
    var data = [...];

    // ...

    if (lastChart) {
        lastChart.destroy();
    }
    lastChart = new Chart(ctx);
    lastChart.Pie(data);
}

I hope that fixes it for you! At least the jumpiness should go away.

@ecofriend
Copy link
Author

Thanks for the suggestion! It fixed the jitter!
Thanks also for pointing out the problem with the chart being created twice. :)

@froatsnook
Copy link

OK great. Glad I could help :).

@dandv
Copy link

dandv commented Aug 17, 2016

Thanks for the suggestion! It fixed the jitter!

@ecofriend: would this be a reason to provide an actual Meteor wrapper for Chart.js, vs. just using it from npm?

@ecofriend
Copy link
Author

@dandv sorry, I can't answer that question with any confidence.

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