1👍
✅
Usually I set up my objects and arrays how I need them at first and then fill them with data.
Set it up:
var chartData = {
datasets: [{
label: 'Test',
data: []
}]
}
Fill it with data:
for (var i = 0; i < yWerte.length; i++) {
chartData.datasets[0].data.push(
{
x: xWerte[i], // You don't need "xWerte", you can simply use "i" when it's always the increment
y: yWerte[i]
}
)
}
You don’t need your c
to save your data, you can just use it like I did. But if you want c
you can save the result of the for-loop in the empty array c
and then use chartData.datasets[0].data = c
.
Working example with live-preview: https://jsbin.com/copiwefaza/edit?js,output
Source:stackexchange.com