This is my script of a VueJS component which should show data inside a dashboard.
<script>
import { Chart } from "highcharts-vue";
import Highcharts from "highcharts";
import exportingInit from "highcharts/modules/exporting";
//import stockInit from "highcharts/modules/stock";
//stockInit(Highcharts);
exportingInit(Highcharts);
export default {
props: {
partsdata: {
type: Array
}
},
methods: {
fetchData() {
this.$http.get('http://127.0.0.1:5000/data/')
.then(response => {
return response.json();
}).then(data => {
var result = JSON.parse(data) // eslint-disable-line no-console
console.log(result.Fare) // eslint-disable-line no-console
})
}
},
components: {
highcharts: Chart
},
data() {
return {
chartOptions: {
series: [{
data: [] // sample data
}]
}
}
}
};
</script>
Receiving the data from my backend works fine, but I am unable to get it into the chart. I still struggle how to work with async tasks, so I tried this and failed
this.data.push(result.Fare)
Header.vue?5e07:33 Uncaught (in promise) TypeError: Cannot read property 'push' of undefined at VueComponent.eval (Header.vue?5e07:34)
Can anyone tell me how to do this?
Update: This is my template where I trigger the Method:
<template>
<div>
<button @click="fetchData" class="btn-primary">Get Data</button>
<highcharts
:options="chartOptions"
></highcharts>
</div>
</template>