My challenge is to populate a data array for my chart in the following way:
data: chardata
To achieve this, I initialize a variable like so:
var chartdata = [];
The issue arises when I attempt to fill it with data from a function that should ideally return an array but ends up returning an object instead.
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;
Upon checking the type of the variable, it shows as an object instead of an array. Thus, when I try to set this data to chardata in the chart, it fails due to being recognized as an object rather than an array.
I attempted to convert it to an array using the Object.values(chardata) method, however, this resulted in an empty array even if the object contained values.
This raises the question of what could be going wrong in my implementation?
The exact error message received is as follows:
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="84e7ece5f6f0aaeef7c4b6aabcaab4">[email protected]</a>:7 Uncaught TypeError: Cannot read property 'skip' of undefined
at ce (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a6c5cec7d4d288ccd5e694889e8896">[email protected]</a>:7)
at fe (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e4878c859690ca8e97a4d6cadccad4">[email protected]</a>:7)
at me (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="54373c3526207a3e2714667a6c7a64">[email protected]</a>:7)
at ni.getElementsAtEventForMode (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8be8e3eaf9ffa5e1f8cbb9a5b3a5bb">[email protected]</a>:7)
at ni.handleEvent (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fd9e959c8f89d3978ebdcfd3c5d3cd">[email protected]</a>:7)
at ni.eventHandler (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="395a51584b4d17534a790b17011709">[email protected]</a>:7)
at i (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="73101b1201075d190033415d4b5d43">[email protected]</a>:7)
at HTMLCanvasElement.Fe.<computed> (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="57343f362523793d241765796f7967">[email protected]</a>:7)