-
-
Notifications
You must be signed in to change notification settings - Fork 839
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
Animation with reactivity #34
Comments
Solved for me with adding |
So the steps to reproduce would be, |
No, no data and no labels
With |
Ok thanks. I will check that. |
Are you using the |
yes
|
Hm I can't reproduce it. So I think it could be caused by the API call, because of the async data. Right now, the mixin is pretty simple, it grabs all labels of the old data and new data. In your case Min, Max, Avg. And compares both. With the assumtion, that if a new label appears, it means a new dataset appears. So if they mismatch it simply rerenders the whole chart instance. If they match, it assumes that the data inside the datasets changes, and sets them on the chartjs instance and call However I found another bug #35 where the chart instance does not get destroyed before a new render. Which causes multiple instances. I will investigate further. 🔍 The screenshot however looks like your data[] count missmatches your labels count. You should check the data. |
@hotrush can you update vue-chartjs to 2.3.5 and check if it still buggy? |
2.3.5 is still buggy. i made a test repo to demonstrate this problem https://hotrush.github.io/vue-charts-bug/ as you can see here https://hotrush.github.io/vue-charts-bug/data.json, data is clean and there is no missmatches in labels or values. |
also added a second chart with |
Okay, I think I found the issue with the initial animation. What the mixin is doingThe recativity mixin checks two things:
And based on that information it either
If you datasets arrive it calls renderChart and if data changes it calls update. The checkSo the assumtion is, if a new dataset arrive either a new label is set or the dataset array is bigger / smaller. Then we need a render. If only the data changes, an update() is enough. The ProblemThe problem is, that if you predefine your labels for the datasets and the datasets, the mixin will only update(). Now you set your data with the api call. And we're getting a race condition there. Because the watcher gets triggered by any changes of the chartData prop. However setting your data this way, a race condition appears, because the watcher get triggered but meanwhile your newData is set. If you output the oldData and newData in the watcher mixin, you'll see that they are equal. Because the oldData is equal with the newData no animation appears. The v-if check prevents this. Because it waits for the data to be set properly. However I am not entirely sure, if its a bug. It's a bit of a weird edge case, because you set your datasets and labels before. Right now I can't think of a clean way to change the watcher mixins, to work with this edgecase. WorkaroundWell, one workaround would be the v-if statement. Another would be to set the labels in your api request. This way, the mixin would see the changed datasets and do a render. ....
pricesChartData.datasets[0].data = _.map(response.data.prices_chart, 'min_price_per_day')
pricesChartData.datasets[0].label = 'Max'
pricesChartData.datasets[1].data = _.map(response.data.prices_chart, 'max_price_per_day')
pricesChartData.datasets[1].label = 'Min'
pricesChartData.datasets[2].data = _.map(response.data.prices_chart, 'avg_price_per_day')
... AlternativeAnother alternative would be to implement an small event system and call update and render yourself. I think, chart.js is not really made for async data flow, tho. |
For the issue with the x-axis, I could not really reproduce it. Do you have any additional custom settings? Can you try to set the label in your api call, while mapping your data? And see if it changes? You could also enable grid lines on the axis to see, if maybe only the labels got an offset.
|
So, finally for axes: according this issue #29 But for animation i am still using Thanks a lot for your help! Can close this issue i think |
If chart has empty initial labels and data and they are updated dynamically - appear animation not working. Do you know how i can fix this?
Environment
The text was updated successfully, but these errors were encountered: