2013-12-11 39 views
0

this link上,使用硬編碼數據在GAS中準備了一個圖表,他們提到您可以從SpreadsheetApp獲取數據。電子表格數據中的GAS柱形圖

請有人可以幫助我 - 如何從電子表格在GAS圖表中構建數據表(列,行)。

我嘗試以下,但沒有成功

var ss = SpreadsheetApp.openById("myid"); 
var datatable = ss.getSheetByName("Chart sheet").getRange("A1:H4").getValues(); 

var chart = Charts.newColumnChart()  
    .setDataTable(dataTable)  
    .setRange(0, 40) 
    .setTitle('Chart') 
    .setLegendPosition(Charts.Position.BOTTOM) 
    .setDimensions(600, 300) 
    .build(); 

我已經使用了代碼的doGet功能,輸出返回以下錯誤: -

Cannot call overloaded constructor setDataTable with parameters (object) because there is more than one matching constructor signature: interface (class) setDataTable(DataTableBuilder) interface (class) setDataTable(DataTableSource) 

回答

2

在你的情況這是唯一的事情錯誤的是,您在獲取範圍(第2行)後調用getValues。要解決它只是刪除getValues()。見代碼固定波紋管:

var ss = SpreadsheetApp.openById("myid"); 
var datatable = ss.getSheetByName("Chart sheet").getRange("A1:H4"); 

var chart = Charts.newColumnChart()  
    .setDataTable(dataTable)  
    .setRange(0, 40) 
    .setTitle('Chart') 
    .setLegendPosition(Charts.Position.BOTTOM) 
    .setDimensions(600, 300) 
    .build(); 

該API可以找到here

+0

哈哈.....很多時間花在這麼小的事情.....好的學習經驗...... – Vasim

相關問題