0
我們是angularjs v4的新手。我們需要在Google圖表中顯示深入圖表。我們正在使用ng2-google-charts指令。我們能夠找到選擇事件並更新數據。但圖表不重新加載。任何人都可以幫助解決這個問題。使用google圖表指令在角度js中鑽取圖表
視圖:index.html的
<pre>
<br/>
<google-chart #drillchart [data]='pieChartData' type="BarChart" (chartSelect)='select($event)'>
</google-chart>
</pre>
Component.ts:
pieChartData = {
chartType: 'BarChart',
dataTable: [
['Country', 'Poulation'],
['Ind', 25],
['Rus', 10],
['Chi', 30],
['USA', 15],
['UK', 12],
['Aus', 8]
],
options: {'title': 'Population'}
};
newDataIndia = [
['State', 'Poulation'],
['AndhraPradesh', 30],
['UttarPradesh', 40],
['MadyaPradesh', 10],
['Karnataka', 10],
['Tamilnadu', 10]
];
newDataUS = [
['State', 'Poulation'],
['Texas', 30],
['Florida', 40],
['Pennsylvania', 10],
['Lousiana', 15],
['Colorado', 10]
];
public changeData(data):void {
/*let dataTable = this.drillchart.wrapper.getDataTable();
for (let i = 0; i < 6; i++) {
dataTable.setValue(i, 1, Math.round(Math.random() * 1000));
dataTable.setValue(i, 2, Math.round(Math.random() * 1000));
}*/
let dataTable = this.drillchart.wrapper.getDataTable()
console.log(dataTable);
dataTable.Sf[0].label = data[0][0];
dataTable.Sf[0].type = "string";
dataTable.Sf[1].label = data[0][1];
dataTable.Sf[1].type = "number";
for (let i = 0; i < data.length-1; i++) {
dataTable.Tf[i].c[0].v = data[i+1][0];
dataTable.Tf[i].c[1].v = data[i+1][1];
}
if(dataTable.Tf.length < data.length-1)
{
for(var icount = data.length-1; icount != data.length-1; icount--) {
dataTable = dataTable.Tf.pop();
}
}
this.drillchart.redraw();
}
預先感謝。