I am using angular2-chartjs to create a chart. Below is my code
Module
import { ChartModule } from 'angular2-chartjs';
View
<div class="col-md-4">
Login Frequency Filter
<button (click)="handleClick($event)" type="button">Update Data</button>
</div>
<div class="col-md-8">
<nb-card>
<nb-card-header>Login Frequency</nb-card-header>
<nb-card-body>
<chart #loginChart id="chart" type="line" [data]="data" [options]="pieoptions"></chart>
</nb-card-body>
</nb-card>
</div>
and this is my component
data: any;
handleClick(event: Event) {
this.data['datasets'][0] = [99,88,88,77];
}
ngAfterViewInit() {
this.themeSubscription = this.theme.getJsTheme().subscribe(config => {
const colors: any = config.variables;
const echarts: any = config.variables.echarts;
const chartjs: any = config.variables.chartjs;
this.data = {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [ {
data: [18, 48, 77, 9, 100, 27, 40],
label: 'Events',
backgroundColor: NbColorHelper.hexToRgbA(colors.info, 0.3),
borderColor: colors.info,
},
],
};
});
}
I was thinking if I update the data in the button click event then it should update the data in the chart automatically which I am seeing the data getting updated but chart is not redrwan
handleClick(updated) {
if(updated)
{
// compute new data and store in this.datasets
this.data.datasets[0].data = [99,99,99,99,99,99,99];
// just trying refresh full variable
this.data = this.data.slice();
}
}
Thanks