我正在尝试使用 ng2-chart 动态创建图表,我从 angular 2 服务获取信息,当我只更改图表的标签时它有效,当我更改数据时只有它有效,但是当我同时更改时,数据都会更新在图表中。有任何人解释这种奇怪的行为。
我的模板:
<canvas baseChart height="130" width="180"  
    [data]="doughnutChartData"
    [labels]="doughnutChartLabels"
    [chartType]="doughnutChartType"
    (chartHover)="chartHovered($event)"
    (chartClick)="chartClicked($event)">
</canvas>
我的课 :
export class PlDoughnutComponent implements OnInit {
  constructor(private homeService: TileServiceService) { }
  ngOnInit() {
    this.updatePLdoughnut();
  }
  public util : UtilService = new UtilService();
  public doughnutChartLabels:string[] = ['Download Sales'];
  public doughnutChartData:number[] = [0,0,100];
  public doughnutChartType:string = 'doughnut';
  public updatePLdoughnut(){
    this.homeService.getTile().
    then(res => {
      this.doughnutChartLabels =  res.PLtypes;
      this.doughnutChartData = this.util.objectToIntArray(res.PLByTypes);
    })
  }
}