I have a data table that retrieves arrays of data and I would like to be able to display them in the form of streaming data curves.
Here is a screen of my datatable :
Here is the code that is supposed to process this data :
async getCanR(CanRArr) {
return fetch('http://pathtomydatatable/', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
})
.then(res => res.text())
.then((result) => {
const data = JSON.parse(result);
let newData = [];
let element;
data.forEach(d => {
const {
can_r_led,
} = d;
console.log(d);
can_r_led.forEach(element =>
console.log(element),
console.log('element est un ' + typeof(element)),
),
console.log('can-r-led est un ' + typeof(can_r_led));
newData.push({
x: Date.now(),
y: can_r_led[0].element,
});
console.log('new data = ')
console.log(newData);
CanRArr.push(newData);
return newData;
});
})
.catch((error) => {
console.log(error)
});
},
the first data.forEach loop goes through my data table and selects the last received row. The second loop can_r_led.forEach parses the objectc can_r_led .
Only, I have this error "Cannot read properties of undefined reading 'element'
'console.log(element)' working correctly.
I guess problem is on ligne 'y: can_r_led[0].element,'