The following code manages to update the results array but the changes only become visible when I hover over the chart as if it only updates on onFocus events. Is there a way to make the chart element update along with the results array?
<ngx-charts-bar-vertical
[results]="chartdata"
xAxis=true
yAxis=true
>
</ngx-charts-bar-vertical>
ngOnInit() {
this.chartdata = [
{
"name": "entry1",
"value": 500
},
{
"name": "entry2",
"value": 700
},
{
"name": "entry3",
"value": 20
},
{
"name": "entry4",
"value": 100
}
];
this.ngZone.runOutsideAngular(() => {
this.interval = setInterval(() => {
this.chartdata.push({name: "entry " + Date.now().toString(), value: 150});
this.chartdata = [...this.chartdata];
}, 3000); //3 seconds
});
}
Angular version: 11 "@swimlane/ngx-charts": "^18.0.1",
*Edit
As Michael D pointed out the problem was with my implementation of ngzone.
The loop could be constructed in the following ways
this.ngZone.runOutsideAngular(() => {
this.ngZone.run(()=> {
this.interval = setInterval(() => {
console.log("refreshing");
this.chartdata.push({name: "entry" + Date.now().toString(), value: 150});
this.chartdata = [...this.chartdata];
}, 3000); //3 seconds
});
}); // One minute
or
this.interval = setInterval(() => {
console.log("refreshing");
this.chartdata.push({name: "entry" + Date.now().toString(), value: 150});
this.chartdata = [...this.chartdata];
}, 3000); //3 seconds