Chartjs-How to plot data coming async in a chartjs chart

0👍

After a lot of experimenting and reading I figured how, I don’t know if it is the best or correct way but it’s working.

The service is fine, the call haves to look like

    var bodyFatChartInstance = new Chart(this.bodyfatRef.nativeElement, this.bodyfatService.getChartConfig());

    this.bodyfatService.getChart().then(function(data)
    {
      console.log(data);
      data["data"]["datasets"][0]["data"].forEach(element => {
        console.log(element);
        bodyFatChartInstance.data.datasets[0].data.push(element);
      });

      data["data"]["labels"].forEach(element => {
       bodyFatChartInstance.data.labels.push(element); 
      });

      bodyFatChartInstance.update();
    });

Leave a comment