[Vuejs]-How to add values to an array from variables in Vue.Js to make bar chart

0👍

It depends on how the data is structured when it comes back from the database. At the most basic, you’d loop through an array or object from the database and call Array.push for each element.. Ex: series.push(x)

This may help:

How do I push items into an array in the data object in Vuejs? Vue seems not to be watching the .push() method

0👍

Assuming that you have a model like :

let barChart = {
  services: [
    ServiceArea1Total,
    ServiceArea2Total,                    
    ServiceArea3Total,
    ServiceArea4Total,
    ServiceArea5Total,
  ],
  labels: ['Western', 'Northern', 'Eastern', 'Southern', 'Central'],
  series: []
}

You are storing your services call in barChart.services, your labels in barChart.labels (which is not used here) and your total series in barChart.series.
For getting all your data from your services and storing it in barChart.series you have to do something like :

barChart.services.forEach( function( service ){
    barChart.series.push( service() );
});

With that code you gonna call all your functions in services and push the data in the array series for each one.

May I have miss understood what you are trying to do ?

Leave a comment