i want to load in a data array for my chart like this:
data: chardata
I create a variable like this:
var chartdata = [];
i fill it with data from a function which should return an array but it returns an object
function getChartData(type) {
var chartdata = [];
console.log(typeof chartdata);
getDates(14).forEach(element => {
var lastdate = new Date(element);
lastdate.setHours(23);
lastdate.setMinutes(59);
lastdate.setSeconds(59);
modlogRef.where("userName", "==", modname).where("action", "==", type).where("timestamp", ">=", element).where("timestamp", "<=", lastdate)
.get()
.then(function(querySnapshot) {
chartdata.push(querySnapshot.size);
})
.catch(function(error) {
console.log("Error getting documents: ", error);
});
});
console.log(typeof chartdata);
return chartdata;
and when i look what type it is it says object put it shoud be a array?
so when i return it to the chart and set data to chardata it fails because it is a object not an array?
I even tried converting it to an array like this:
Object.values(chardata)
but that is just an empty array even if the object had values?
What am i doing wrong?
The error that i get is:
[email protected]:7 Uncaught TypeError: Cannot read property 'skip' of undefined
at ce ([email protected]:7)
at fe ([email protected]:7)
at me ([email protected]:7)
at ni.getElementsAtEventForMode ([email protected]:7)
at ni.handleEvent ([email protected]:7)
at ni.eventHandler ([email protected]:7)
at i ([email protected]:7)
at HTMLCanvasElement.Fe.<computed> ([email protected]:7)
question from:
https://stackoverflow.com/questions/65863791/javascript-chart-js-data-object-array 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…