Chartjs-Problem extending data series in Chart.js

2👍

You should push your new data into chartData object as per the yAxisID. try the following code.

 function addData(chart,label, data) {
    chart.data.labels.push(label);        

    for(var i=0; i< data.length; i++){
       for(var k=0; k< chartData.datasets.length; k++){
          if(chartData.datasets[k].yAxisID == data[i].yAxisID){
              chartData.datasets[k].data.push(data[i].value);
            }
          }
        }   
       chart.update();
       console.log(chart.data);
     }

  var yArr = [ {yAxisID:"F", value: 64},{yAxisID:"G", value: 1.01} ];
  addData(myChart,'Sat', yArr);

https://jsfiddle.net/5botxckf/

Leave a comment