Currently facing a rather frustrating issue. I'm attempting to utilize D3.js for dynamically plotting data (specifically, scores of individuals).
- Retrieving record data from a firebase database whenever changes occur - this is represented by an object containing static score data.
- Adding a time key/value pair to the record.
- Preparing the data for D3 by creating an array named 'data' where the record is added every second using data.push(record).
- While successfully outputting the record object to the console as intended, encountering issues with the time value displaying in a loop - it's showing the current time value for all elements, including past ones.
It has been approximately 3 hours since I got stuck on this problem.
If anyone can provide assistance, it would be greatly appreciated. Thank you.
var data = [];
record = {Fanny: 40, Joe: 20};
var time = 0;
record["time"] = time;
console.log(record);
myTimer = setInterval(function () {
time = time + 1;
record.time = time;
console.log(record);
data.push(record);
for (i = 0; i < data.length; i++) {
console.log(data[i].time)
}
},1000);