Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

91
Views
Update data in Barchart from API in Vue

Calling an Api to get the values and putting them in the List but the list in data function is not being updated.

created() {
  // API CALL FOR BARCHAR
  var getStandardBarchart = async() => {
  //var currentarray =[]

  // API CALL TO KEIKAI for BARCGARTS
  var myHeaders = new Headers();
   myHeaders.append("Content-Type", "application/json");
   //var raw = JSON.stringify({"input_values": input_values, "output_values": output_values});
   var raw = JSON.stringify({"input_values": {},"output_values": [ "barchart1","barchart2","barchart3","barchart4","barchart5","barchart6","barchart7","barchart8"  ]});

   var requestOptions = {
     method: 'POST',
     headers: myHeaders,
     body: raw,
     redirect: 'follow'
   };


   await fetch("/api", requestOptions)
     .then(response => response.json())
     .then(result => {
        var barChart = [];

        //var value
        Object.keys(result).forEach(function(key) {
        let specificValue = parseInt(result[key])
          barChart.push(specificValue) 
        })
        console.log(barChart)
        console.log(this.Agricultural_production_Animal_production_Cattle[1].imagecontent.barchart1.values[0][2])
       // this.Agricultural_production_Animal_production_Cattle[1].imagecontent.barchart1.values[0][1]=15

        // this.Agricultural_production_Animal_production_Cattle[1].imagecontent.barchart1.values[0] = barChart.splice(0, 4);
        // this.Agricultural_production_Animal_production_Cattle[1].imagecontent.barchart1.values[1] = barChart.splice(0, 4);


      })
     .catch(error => console.log('error', error));



 }

getStandardBarchart()
}

What I want is that the values in the data function should be updated by the barchart[] list. But if I push something in list before api or give some default value to the list it is not undefined in Values : [barchart[0]] gives undefined.

data:function(){
  {imagecontent:
    
   {barchart1:{barid: "bar_Agricultural_production_Animal_production_Cattle",names:["sdjhfb", "derfgas", "Pdft", "dfdfs", "dfsdfat"],
   values:[[barchart[0], 10, 5, 150],[87, 80, 25, 35]],
   textxaxis:["future", "present"] }}
   }]
  }
}
7 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs