-
-
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
Mixins don't seem to trigger a refresh of the chart #44
Comments
Seems that sometimes the watch: {
'chartData': function () {}
} does not trigger a change. Right not I am not exactly sure why and when. |
The way how I have solved it is that instead of just adding one element to the array I actually recreate the array. Not ideal but it seems to work. However since the latest update to Vue 2.2 things have gotten a bit 'weirder'. I now get a undefined error on this.chartId whenever I change any data on the page. Will create a separate issue for this, however it might be webpack related. You can close this issue unless you want to keep on digging. Great work on the package by the way! |
Well I leave it open because this watcher bug seems to apear from time to time like in #41 Yeah with vue 2.2 some things changed. I still need to update the dependencies and do some testing before I merge. |
Well a few points here, about your example, as I tried to repoduce the bug. FirstYou don't need the SecondYou should not name your data property the same as the line-chart prop. As data properties, Poprs and computed properties share all the same namespace. This could lead to some problems! I think kind of the problem is, that you're setting the data one by one directly on your data property. Furthermore its not the best idea to pass the data one by one. Because in the worst case scenario the data would be passed to the prop while incomplete and the mixin would rerender the chart or update it. And I don't know how forgiving chart.js is if you have bad data passed to the render function. The mixins are also pretty generic. And does not fit all use cases. However you can implement it by your own, pretty easy. You could also make it event based and if you finished changing your data emit an event
You can also update to the latest version of |
Hello, i got same issue, and i found that if you push on charts labels it is updating, but not working when i updating props, is there any solution how to slove it? |
Can you provide some sample code ? |
Hi, i found what is a problem in, all in vue.$watch. |
Hi, I got the same issue here, I only send the percentages to the Pie chart not the whole 'chartData' and I used my own watcher. so the I got the same problem described by @berendberendsen at the first comment, after a lot of headache with it I've found out that I was assigning the data instead of changing the object as @SemyonL95 said before me. so after I used 'push' instead of simple assignment of data it worked. // inside parent component:
// not working code
...
this.chartData[0] = 70
this.chartData[1] = 30
...
// working code
...
this.chartData.push(70)
this.chartData.push(30)
...
// inside child component pieChart.js
...
props:['chartData']
...
datasets:[{ ...
data: this.chartData
}] after having a look at the difference of direct assignement and push, it's all about performance but they do the same thing so if someone could care for an explanation it might show the solution to this weird bug. |
@thegreyfellow I believe it has to do with Vue itself and more deeply with JS in general, not with vue-chartjs. Changes like you describe are not identifyable, see Particularly for array you can do |
@quicky84 Yes after reading these posts I understood the issue, as you said it is not related to the library neither the VueJS, but a JS issue. Thanks for the explanation :) . |
Thanks @quicky84 for the find. Additionally there is a note on vm.$watch
I added it to the docs, I guess I can close here. |
Sorry to re-comment here but you should re-check the link you put on the docs it has an address of localhost:8080. I hope I'm not wrong |
Ups 🙈 , fixed it now. |
I did like below and it is working reactively that way :)
|
Oh yeah, that would be a good workaround to use |
Here is what I came up with: In the parent component:
Then in child component:
|
Here's my method, which IMO is the easiest solution, for parent to child component data. First, assign your chart component a ref on the parent component. i.e. In your chart component, I remove all reactive mixing stuff. Not needed. Then I created the following methods:
Finally, in your parent, create a method along of the lines of this to update your data:
|
or
|
Github should have a "pin comment" feature for answers like this. Thanks @mbarwick83 |
Expected Behavior
Adding a label and value to the dataset should add the item to the chart
Actual Behavior
Adding a label and value to the data doesn't change the chart. The chart only gets redrawn when I resize the browser
Line chart:
Component:
I would expect that the addData function triggers a change in the prop and therefor a redraw in the chart.
Vue chartjs version 2.3.7
The text was updated successfully, but these errors were encountered: