How to update barchart from angular2? I am trying to add new entry on click to [datasets]="barChartData"
In template, graph looks like this:
<canvas baseChart #myChart
[datasets]="barChartData"
[labels]="barChartLabels"
[options]="barChartOptions"
[legend]="barChartLegend"
[chartType]="barChartType"
(chartHover)="chartHovered($event)"
(chartClick)="chartClicked($event)"></canvas>
I tried following recommended methods: 1) Changed dataset variable directly - cloned the data , changed it and then assigned it. This way I can change/update exsiting data but I can't add new entry to dataset.
2) ChangeDetectorRef, I added private ref: ChangeDetectorRef to constructor and called ref.detectChanges()
on updates. but no luck. I also tried using ApplicationRef.
In both cases, in debug window, I can see that barChartData is updated with new values in ts file, but template(html) is not updated/refreshed.