ng2-chart:为什么更新数据和标签后图表的颜色会改变?

时间:2019-03-25 16:08:38

标签: angular ng2-charts

当我更新图表时,我有一个ng2-chart库的条形图有角度 数据和标签改变了,但是颜色变成了灰色! 为什么?

我尝试通过以下方式更新

  • chart.chart.update();
  • chart.ngOnChanges({});
  • this.isDataLoaded = false; setTimeout(function(){this.isDataLoaded = true},0);

    // component.html

    <div style="display: block">
          <canvas baseChart 
                 [datasets]="chartMonthData"
                 [labels]="selectedMonthLabels"
                 [options]="barChartOptions"
                 [plugins]="barChartPlugins" 
                 legend=false
                  chartType="bar">
            </canvas>
     </div>
    

1 个答案:

答案 0 :(得分:0)

这是解决方案,不知道为什么以前不起作用:

 this.isDataLoaded=false;
         setTimeout(() => {
          this.isDataLoaded=true;
         }, 0); 
相关问题