I've been working on pulling JSON responses from an API to use in a Chart.js chart within my Vue component. Here's the JavaScript code snippet I'm using:
import LineChart from './LineChart.js'
export default {
name: 'Chart',
components: LineChart,
data () {
return {
loaded: false,
stockData: {
labels: null,
datasets: null
}
}
},
async mounted () {
this.loaded = false
try{
const response = await fetch('http://localhost/AAPL')
const stock = await response.json()
console.log(stock)
let annual = stock.Earnings.Annual
for(let i of annual){
this.stockData.labels.push(i.date)
this.stockData.datasets.push(i.epsActual)
}
this.loaded = true
} catch (e){
console.error(e)
}
}
}
However, I encountered an error message stating:
Chart.vue?36ee:38 TypeError: annual[Symbol.iterator] is not a function
Does anyone have suggestions on how to successfully incorporate this data into the chart?