-
-
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
Loading data from server and displaying #78
Comments
Well, you don't need to use Vue's You can simply make your api call in the However your But keep in mind the limitations to the watcher. There are also some issues related to this: #44 #34 |
Hi @cdubant I recently had to implement something like this and I was kinda stuck. Here's what I did (with help from Vuex); First thing I did was store what I needed from the API call in Vuex so I could pretty much access it anywhere. Then I wrote a
And then in my I hope that was useful to you 😄 |
@apertureless the thing is that even if I do the following LineChart.vue
LineChart.js
The fillData method never gets triggered, I never see the API call. When I add a button to trigger this method, then the API call is made and the data is displayed just fine. The thing is that I can't have my users perform any action before displaying the charts, it would make no sense on an ergonomic POV. @yomete Thanks for your insight but I'm afraid I'm not familiar with Vuex so it might be a little overkill to implement / configure Vuex for my (I hope) "simple" requirement. Anyway thanks again for providing a solution. |
Well, your mounted () {
this.fillData();
}, Besides: I don't really understand why you have two LineChart components? Also with the exact same name. Is there a reason behind this? |
@apertureless you're right, though it doesn't help in rendering the chart. After fixing the method call, I saw the API call but it didn't help in rendering the graph. I created 2 different files because of http://vue-chartjs.org/#/home?id=reactive-data (I can see a js file and something that looks like a vue file, that's why I created both). I found a simpler solution by having a single component and doing the following (as simple as that)
It now works as expected, thanks for your time. 👍 |
Have the same problem - chart is not redrawn after datasets change. |
Can you prodive a jsfiddle / codepen ? For reproduction? It heavily depends on how you populate your data, if you're using the reactive prop etc. |
@apertureless I can provide code here because I use API requests. My vue component looks like this:
And PieChart.js:
|
You could try the solution mentioned here #10 (comment) The problem is like mentioned in #44 the limitations
If it's not working you could try an event based system, where you trigger an event and listen on it and then call update() yourself. |
@apertureless anyway can't make it work. Vue Devtools shows me that the data is successfully changed, but the pie chart is still empty: If I click on the label, the chart is redrawn, but not automatically. reactiveProp instructions didn't help me too. |
Have you tried the solution mention in #10 ? Like I said, not really |
@apertureless yes, I changed my code like this:
But in my case it doesn't help me, don't know why |
@moonlik |
@dwk715 Not yet, I have no idea how to solve it for now |
Well you could fire an event if new data arrives and then re-render or update the chart instance. |
Expected Behavior
In the example for Reactive Data in the docs, when implemented, you have to click the "Randomize" button to trigger the fillData function and get content displayed in the graph.
Actual Behavior
I'm looking for a way (as I serve the content to display from an API) to display the data as soon as the component gets a response from my API.
I tried to do the usual Vue 2.0 nextTick to call the fillData function when the component is mounted
Below is the code of my component (slightly adapted to match my API call), of course it works perfectly when I click the "Randomize" button but I don't want to have to click this button for each and every graph in my "Dashboard" component (several graphs in this component).
Thank you in advance for your help !
Environment
The text was updated successfully, but these errors were encountered: