score:0

Accepted answer

to start, you don't need a foreach here otherwise you will push 4 data in the dataset while you are declaring 2 :

dataplot.data.datasets.foreach((dataset)=> {
      dataset.data.push(data);
      dataset.data.push(data2);
 });

try one of those 2 options :

doing things manually (without foreach):

dataplot.data.datasets.push(data);
dataplot.data.datasets.push(data2);

or, create an array of data, and make the foreach on that array :

dataarray.foreach( (item) => {
    dataplot.data.datasets.push(item);
});

ps : for the second option, you need to make sure that dataarray.length == dataplot.data.datasets.length


Related Query

More Query from same tag