我正在尝试将数据表和图表值转换为 % 格式;我的一些数据是数字,一些像 datasource [0] [3] 和 datasource [0] [6] 是百分比。
如何将其转换为“%00.00”格式?我尝试使用.setNumberFormat("#.###%);
,但我无法让它工作。
以下是我的部分代码:
function doGet() {
var uiApp = UiApp.createApplication();
var ssKey = "0Ao5bdXU44DOpdDg5YVB4UGxpSXI5a1hkcjVhZmlETWc";
var ss = SpreadsheetApp.openById(ssKey);
var datasource = ss.getRangeByName("a1:ae49").getValues();
Logger.log(datasource);
var data = Charts.newDataTable()
.addColumn(Charts.ColumnType.STRING, datasource [0] [0])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [1])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [2])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [3])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [4])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [5])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [6])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [7])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [8])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [9])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [10])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [11])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [12])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [13])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [14])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [15])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [16])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [17])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [18])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [19])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [20])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [21])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [22])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [23])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [24])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [25])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [26])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [27])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [28])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [29])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [30])
for (i=1;i<=datasource.length-1;i++){
Logger.log(datasource [i]);
data.addRow([datasource [i] [0], datasource [i] [1], datasource [i] [2], datasource [i] [3], datasource [i] [4], datasource [i] [5], datasource [i] [6], datasource [i] [7], datasource [i] [8], datasource [i] [9], datasource [i] [10], datasource [i] [11], datasource [i] [12], datasource [i] [13], datasource [i] [14], datasource [i] [15], datasource [i] [16], datasource [i] [17], datasource [i] [18], datasource [i] [19], datasource [i] [20], datasource [i] [21], datasource [i] [22], datasource [i] [23], datasource [i] [24], datasource [i] [25], datasource [i] [26], datasource [i] [27], datasource [i] [28], datasource [i] [29], datasource [i] [30]])
};
data.build();
var monthFilter = Charts.newCategoryFilter()
.setFilterColumnLabel("Months")
.build();
var dashboard = Charts.newDashboardPanel()
.setDataTable(data)
.bind([monthFilter],[tableChart])
.bind([monthFilter],[tableChart])
.build();