Computed object won't populate chart
See original GitHub issueExpected Behavior
Passing a prop array and computing a data value from it to populate a chart should work.
Actual Behavior
Empty chart.
Looking in vue console tools, I see that my computed object is present and (seemingly) valid:
actionbarlabels:Object
datasets:Object
data:Array[4]
0:4
1:1
2:2
3:1
labels:Array[4]
0:"call"
1:"join"
2:"attend meeting"
3:"attend march
And my template code looks like this:
<bar-chart :data="actionbarlabels" :options="{responsive: true, maintainAspectRatio: false}"></bar-chart>
Environment
- vue.js version: 2.3.4
- vue-chart.js version: 2.8.2
- npm version: 4.2.0
- quasar version: 0.14.0
Issue Analytics
- State:
- Created 6 years ago
- Comments:19 (6 by maintainers)
Top Results From Across the Web
Chart JS not reacting to change in computed property
A simple fix is passing a cloned object. drilldownData() { if (this.toggle_drill === "up") { return JSON.parse(JSON.stringify(this.
Read more >Computed Properties - Vue.js
Think of a computed property as declaratively describing how to derive a value based on other values - its only responsibility should be...
Read more >Pivot table cannot create calculated item - Super User
Try this: On the actual pivot table, right click the columns months, select Ungroup. enter image description here.
Read more >Specify Computed Columns in a Table - SQL Server
Right-click Columns and select New Column. Enter the column name and accept the default data type (nchar(10)).
Read more >Use Excel Pivot Table Calculated Field or Calculated Item
If you create a calculated item in a field, the following restrictions will be placed on that pivot field: You will NOT be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oh, you are working with an API ? Well, please keep in mind that if you’re using api calls with
axios
orfetch
that they are async!So your chart component will get created and mounted before your data arrives.
You could use a
loading
state.So in your
data()
you defineand in your api call (if you’re using axios) you could set it it to true.
And then add an
v-if="loaded"
to your chart component. So it will only be shown if your data is complete.Another way would be to add a watcher and rerender the chart if your computed prop change.
You can check out the resources in the docs. There are some tutorials on how to interact with APIS
http://vue-chartjs.org/#/home?id=resources
You’re welcome! ✌️