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

hello a q about reactivity #28

Closed
SerjoA opened this issue Jan 8, 2017 · 13 comments
Closed

hello a q about reactivity #28

SerjoA opened this issue Jan 8, 2017 · 13 comments

Comments

@SerjoA
Copy link

SerjoA commented Jan 8, 2017

cant get to make the reactive prop to update the chart although it shows that the data has been changed the chart wont update or redraw
can anyone please post example , btw iam on vue 2.1

@apertureless
Copy link
Owner

Hey,

here is an example: https://github.com/apertureless/vue-chartjs/blob/master/src/examples/ReactiveExample.js

which is also used on the demo page.

If you have issues, please provide a jsfiddle or a minimal repo for reproduction.

However the mixins are very generic. It may be better if you implement an update cyrcle yourself.

Heres the source of the mixin: https://github.com/apertureless/vue-chartjs/blob/master/src/mixins/reactiveProp.js

You can copy paste it as a local mixin and try to add debug output. See if the watcher triggers and if

if (JSON.stringify(newDataLabels) === JSON.stringify(oldDataLabels)) works.

@SerjoA
Copy link
Author

SerjoA commented Jan 8, 2017

checked examples but still wont work, heres a jsfiddle
https://jsfiddle.net/Solutionseje/7bgqzw4s/

@SerjoA
Copy link
Author

SerjoA commented Jan 8, 2017

i solved it with emitting events and updating chart manually
but is there another way?

@SerjoA
Copy link
Author

SerjoA commented Jan 8, 2017

now i have another problem when moving through routes, without keep-alive

Uncaught (in promise) TypeError: Cannot read property 'getContext' of undefined
at VueComponent.renderChart (eval at (app.js:1128), :41642:59)
at VueComponent.boundFn [as renderChart] (eval at (app.js:1128), :338:15)
at VueComponent.updtChrt (eval at (app.js:2274), :23:12)
at Vue$3.boundFn (eval at (app.js:1128), :340:13)
at Vue$3.Vue.$emit (eval at (app.js:604), :2393:16

@apertureless
Copy link
Owner

Hey @SerjoA

Reactivity

well events are one way to go. Chartjs has no automatic detection if data changes. So you actually always have to manually update the chart / rerender.

Generally there are two ways: one is over events, the other is over the watcher (the mixins are using it) However it can be, that you have to add deep: true to the watcher, because if the data is rather complex it would not see a change.

Thanks for the jsfiddle.

Eh, there are two mixins reactiveProp and reactiveData.

You should use reactiveData only if you store your chartdata into a variable in the data function. Thats for, if you get your data over an api.

If you pass your chartdata as a prop like in your jsfiddle, you should use the reactiveProp mixin.

vue-router

Never used it with vue-router. Do you have a minimal repo to reproduce the error? Hard to debug it without seeing the code.

@SerjoA
Copy link
Author

SerjoA commented Jan 10, 2017

Thnx alot for the info, I'll try to post my code with vue router, ATM I am sick but will do that when I've got a chance, solved all problems BTW with events, added update chart upon event because the mixins somehow didn't work, plus my update chart function basically does, context= chart-id, new chart (context, data) and it worked

@SerjoA
Copy link
Author

SerjoA commented Jan 10, 2017

Thnx for the repo, you are awesome

@apertureless
Copy link
Owner

Did you tried both mixins? Also the reactiveProp one?

What are you doing, is creating a new chart instance if new data arrives.
Which is not a good idea, because it may not destroy the old instances properly.

You actually need only to call this._chart.update()

@SerjoA
Copy link
Author

SerjoA commented Jan 11, 2017

thank you for the info, will try it and update you, still sick :(
btw i tried both mixins

@SerjoA
Copy link
Author

SerjoA commented Jan 12, 2017

hi, i tried this._chart.update() works good

@SerjoA
Copy link
Author

SerjoA commented Jan 12, 2017

thank you

@apertureless
Copy link
Owner

Ok, cool.
So can this issue be closed?

@SerjoA
Copy link
Author

SerjoA commented Jan 12, 2017 via email

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

2 participants