私は現在、さまざまなシート (一部ではタブとも呼ばれます!?) にまたがる数年分の数値データを含むスプレッドシートを使用しています。各シート/タブは 1 年分の価値を表しています。いくつかのオンライン チュートリアルに従って、特定の年の簡単なグラフ ダッシュボードを作成しました。これは、Serge の回答を読んだ後に 2 つの変更を加えた (「ss」をグローバルにし、setActiveSheet を使用する) ことで、これまでのコードの一部です (グラフを描画する部分を除く)。
var ss = SpreadsheetApp.openById(ssID);
ss.setActiveSheet(ss.getSheetByName("2012"));
function doGet() {
var sheet = ss.getActiveSheet();
var data = sheet.getRange(1,1,sheet.getMaxRows(),sheet.getMaxColumns());
var dashboard = Charts.newDashboardPanel()
.setDataTable(data)
.build();
var uiApp = UiApp.createApplication().setTitle("My Dashboard");
// Dropdown box
var listBox = uiApp.createListBox() // Choose data by year
.setId('listBox')
.setName('listBox')
.setVisibleItemCount(1);
for (i=0; i<ss.getNumSheets(); i++) {
listBox.addItem(ss.getSheets()[i].getSheetName());
}
var infoLabel = uiApp.createLabel('Select from List').setId('info').setVisible(false);
// Add a handler to the ListBox when its value is changed
var handler = uiApp.createServerChangeHandler('showSelectedinfo');
handler.addCallbackElement(listBox);
listBox.addChangeHandler(handler);
// UI Element: Grid
var mygrid = uiApp.createGrid(1, 3);
mygrid.setWidget(0, 0, uiApp.createLabel('By Year:'));
mygrid.setWidget(0, 1, listBox);
mygrid.setWidget(0, 2, infoLabel)
var controlsPanel = uiApp.createVerticalPanel().add(mygrid);
uiApp.add(controlsPanel).add(dashboard);
return uiApp;
}
function showSelectedinfo(e){
var app = UiApp.getActiveApplication();
var selectedItem = e.parameter.listBox;
var listBox = app.getElementById('listBox');
app.getElementById('info').setText('You selected :'+selectedItem).setVisible(true)
.setStyleAttribute('color','#008000');
ss.setActiveSheet(ss.getSheetByName(selectedItem));
return app;
}
ここで、ドロップダウン ボックスを使用して別のシート、つまり年を選択し、それに応じてチャートを更新したいと考えています。ただし、「年」を選択して正しく表示することはできますが、新しいシートのデータを使用するように変更することはできません。おそらく、ここにいる専門家がいくつかの指針を提供できますか?