以编程方式更改数据后重新渲染ng2-google-chart [英] Rerender ng2-google-chart after programmatically changing the data
问题描述
我正在使用ng2-google-chart
,它工作正常.现在,我想使用一些复选框来选择在图表中显示哪些数据.
I am using ng2-google-chart
and it works fine. Now I want to use some checkboxes to choose which data is shown in the graph.
我的图形连接到数组chartData
,在选择后该数组将正确更新.但是图形不会改变.这是我的图
My graph is connected to the array chartData
, which is updated correct after the selection. But the graph does not change. This is my graph
<div #graph [chartData]="this.chartData" chartType="AreaChart" GoogleChart></div>
在更改数据后是否有一种方法可以重新呈现它?
Is there a way to rerender it after the data is changed?
推荐答案
与此同时,我解决了这个问题:
In the mean time I solved this:
在 angular2-google/directives/angular2-google-chart.directive.ts 中导入OnChanges
并实现它:
ngOnChanges(changes) {
if (googleLoaded)
{
this.drawGraph(this.chartOptions,this.chartType,this.chartData,this._element);
}
}
//edit:现在已在最新的库版本中修复.
//edit: This is now fixed in the newest library version.
这篇关于以编程方式更改数据后重新渲染ng2-google-chart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!