1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
export class AppComponent {
// staticData: Point[] = [{x: 5, y: 6}];
staticData: Point[]=[];
randomWalk: Observable<any> ;
title = 'blog-angular-chartjs';
constructor(private http:HttpClient) {
let last = 0;
const source = interval(4000);
const subscribe = source.pipe(
switchMap(() => this.http.get("http://localhost:8080/ecarTypeTime/" + 0 + "/" + Date.now())),
map((data: any) => {
console.log(data);
return {x: data[0].id, y: data[0].courant}
})
).subscribe((res: any) => {
console.log('res 4000 : ', res);
this.staticData.push({x:res.x,y:res.y});
console.log('staticData: ', this.staticData);
});
//
// ajoute la nouvelle donnée {x: .., x:.c .}
// au chart.js
// voir si on peut ajouter en diect des données sur un graphique ou si il faut recréer le chart en entier, je ne sais pas
this.randomWalk = interval(4000)
.pipe(
map(i => (
console.log("interval 3000==>"+this.staticData),
{
x: i,
y: (last += Math.random() * 10 - 5)
}
))
);
}
} |
Partager