[Vuejs]-Manipulating Data in Vue for Chart Options

0👍

First, to be safe, check that datas exists in your computed property. It is set to an array initially, but if invalid data comes back it could cause an error. So you could check something right inside your computed property like if(this.datas && this.datas.length), and only if that is true try to fill in chartdates. Otherwise, return an empty array.

Second, based on the JSON you included, the date can be extracted in the for loop using

this.datas[i].date

What you have now would get the whole object inside { .. } instead of just the date. There’s also a typo using this.data[i] when it should be this.datas[i].

Finally, to make chartdates an array you need to set chartdates[i] to each ith value, otherwise only the last value will be stored in chartdates as Steven pointed out.

0👍

Try this:

<div v-if="datas.length > 0">
<p>{{ datas }}</p>
 {{ getDates }}
</div>

0👍

In this lines of code

getDates() {
  let chartdates;
  for (let i = 0;i< this.datas.length; i++) {
    chartdates = this.data[i];
  }
  return chartdates;
}

may be this.data[i] is replace by this.datas[i];

Leave a comment