[Chartjs]-Update Chart js chart dynamically in angular 2 from data getting from nodejs service

2👍

your empty array is always presented while new data arrives form backend before completing a loop.so please remove your array form the function you called and initiate your empty array at the beginning.

ngOnInit(){
this.time_data = [];
this.water_data = [];
 }

0👍

Where are you calling getTankData every 10 seconds?

Add this to to your TypeScript File:

import { ChangeDetectorRef } from '@angular/core';


 constructor(private ref: ChangeDetectorRef){}

 ngOnInit(){

   //Call it every 10 seconds
   setInterval(this.getTankData(), 10000);
}



 //add an change detector at the end of your getTankData function

   getTankData(){
     ...
    this.ref.detectChanges();
    }

Leave a comment