1

2 つのコントロールと 2 つの縦棒グラフを含むサンプルの Google ビジュアライゼーション ダッシュボードがあり、2 番目の縦棒グラフはデータ テーブルの集計を使用して次のように描画されます。

'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'}]
 ));

すべてのコードは正常に動作します。しかし、問題は、コントロールを選択したときに集計によって作成されたグラフが正しく変更されないことです。そして、同じコントロール オプションを 2 回選択した場合にのみ変更されます。

4

1 に答える 1

2

何時間も頭を割った後、ついに問題を解決しました。

修正のために、2 つのイベント リスナーを使用しました。1 つはreadyイベントで、もう 1 つは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();
 });

この fiddleで更新されたコードを見つけます。

于 2013-04-27T06:33:13.853 に答える