2013-04-26 136 views
1

我有兩個控制,並且其中第二列圖表是使用數據表作爲聚集繪製兩個列圖表樣本谷歌可視化儀表板,谷歌可視化數據分組

'dataTable' : google.visualization.data.group(data, [0], 
[{'column': 2, 'aggregation': google.visualization.data.sum, 'type': 'number'}]) 

和它使用的是重繪中間表格圖,

google.visualization.events.addListener(divPicker, 'statechange', 
function(event) { 
// group the data of the filtered table and set the result in the pie chart. 
columnChart1.setDataTable(google.visualization.data.group(
// get the filtered results 
table.getDataTable(), 
[0], 
[{'column': 2, 'aggregation': google.visualization.data.sum, 'type': 'number'}] 
)); 

所有的代碼工作正常。但問題是,當我選擇控件時,聚合創建的圖表沒有正確更改。只有當我選擇兩次相同的控制選項時,它纔會改變。

+0

**請注意:**我的示例[儀表板位於此處](http://jsfiddle.net/ZCKFc/) – mpsbhat 2013-04-26 13:24:47

回答

2

經過這麼多小時的破解,終於我解決了這個問題。

對於修復,我用了兩個事件偵聽器,其中一個是準備事件等爲statechange事件作爲,

google.visualization.events.addListener(subdivPicker, 'ready', 
function(event) { 
// group the data of the filtered table and set the result in the pie chart. 
columnChart1.setDataTable(google.visualization.data.group(
// get the filtered results 
table.getDataTable(), 
[0], 
[{'column': 2, 'aggregation': google.visualization.data.sum, 'type': 'number'}] 
));  
// redraw the pie chart to reflect changes 
columnChart1.draw(); 
}); 

google.visualization.events.addListener(subdivPicker, 'statechange', 
function(event) { 
// group the data of the filtered table and set the result in the pie chart. 
columnChart1.setDataTable(google.visualization.data.group(
// get the filtered results 
table.getDataTable(), 
[0], 
[{'column': 2, 'aggregation': google.visualization.data.sum, 'type': 'number'}] 
)); 
// redraw the pie chart to reflect changes 
columnChart1.draw(); 
}); 

找到更新的代碼中this fiddle