Currently, I am working on creating a line chart using vue-chart.js.
Here is the Vue component I am utilizing:
Vue.component("line-plot", {
extends: VueChartJs.Line,
props: ["label", "data", "options"],
mounted(){
fetch('api/data/monthlypaid')
.then(response => response.json()
.then(data =>{this.data = data;
console.log(data);
console.log(this.data); #replacing the statement above
}));
this.renderLineChart();
},
methods:{
renderLineChart: function () {
this.renderChart({
labels: this.data["DateReceived"],
datasets: [{
data: this.data ? this.data["AmountPaid"] : []
}]
},
this.options )}
},
watch: {data: function () {
if (this._chart) {
this._chart.destroy();
}
this.renderLineChart();
}
}
})
Following that, I set up my Vue app instance with chart options. However, an issue arose regarding the API data retrieval process. After fetching the data, when checking this.data
in two console.log
statements, one displays the desired JSON output while the other presents an __ob__
. Is there any insight on how to ensure that this.data
actually contains the JSON data obtained from the API call?