我使用Google Chart服务在我的网络应用程序的Google Apps脚本中创建一个表格 现在我有两个问题:
当我添加更多行和列时,列的宽度越来越小,直到出现滚动条的点。我添加了一个代码示例。我可以更改/增加图表的(最大)显示大小,以便没有滚动条吗?
我需要一个字符串列,它与右边对齐。默认值是字符串列的左侧对齐。我怎么能改变这个?是否有更多选项来修改表的格式(文本大小,颜色,粗体等)?
function doGet() {
var app = UiApp.createApplication();
var data = Charts.newDataTable()
.addColumn(Charts.ColumnType.STRING, "Name")
.addColumn(Charts.ColumnType.STRING, "Gender")
.addColumn(Charts.ColumnType.NUMBER, "Age")
.addColumn(Charts.ColumnType.NUMBER, "Donuts eaten")
.addColumn(Charts.ColumnType.NUMBER, "Donuts eaten")
.addColumn(Charts.ColumnType.NUMBER, "Donuts eaten")
.addColumn(Charts.ColumnType.NUMBER, "Donuts eaten")
.addRow(["Michael", "Male", 12, 5])
.addRow(["Michael", "Male", 12, 5])
.addRow(["Elisa", "Female", 20, 7])
.addRow(["Robert", "Male", 7, 3])
.addRow(["John", "Male", 54, 2])
.addRow(["Jessica", "Female", 22, 6])
.addRow(["Aaron", "Male", 3, 1])
.addRow(["Margareth", "Female", 42, 8])
.addRow(["Miranda", "Female", 33, 6])
.addRow(["Miranda", "Female", 33, 6])
.addRow(["Miranda", "Female", 33, 6])
.addRow(["Miranda", "Female", 33, 6])
.addRow(["Miranda", "Female", 33, 6])
.addRow(["Miranda", "Female", 33, 6])
.build();
var tableChart = Charts.newTableChart().setDataTable(data)
.build();
app.add(tableChart);
return app;
}
答案 0 :(得分:3)
关于第1页。有两种方法可以更改图表的宽度和高度。第一个是使用TableChartBuilder
类的setDimensions方法。该方法的缺点是不可能在页面宽度/高度百分比中设置宽度/高度。第二种方法是使用同一类的setOption方法。这种方法没有缺点。以下代码演示了它。
关于第2页。不幸的是,现在无法对齐表格图表的列。据我所知,甚至不可能对齐表格图表下方GWT Table的列。您可以在GAS issue tracker上创建有关此缺陷的功能请求。
function doGet() {
var app = UiApp.createApplication();
var data = Charts.newDataTable()
.addColumn(Charts.ColumnType.STRING, "Name")
.addColumn(Charts.ColumnType.STRING, "Gender")
.addColumn(Charts.ColumnType.NUMBER, "Age")
.addColumn(Charts.ColumnType.NUMBER, "Donuts eaten")
.addColumn(Charts.ColumnType.NUMBER, "Donuts eaten")
.addColumn(Charts.ColumnType.NUMBER, "Donuts eaten")
.addColumn(Charts.ColumnType.NUMBER, "Donuts eaten")
.addRow(["Michael", "Male", 12, 5])
.addRow(["Michael", "Male", 12, 5])
.addRow(["Elisa", "Female", 20, 7])
.addRow(["Robert", "Male", 7, 3])
.addRow(["John", "Male", 54, 2])
.addRow(["Jessica", "Female", 22, 6])
.addRow(["Aaron", "Male", 3, 1])
.addRow(["Margareth", "Female", 42, 8])
.addRow(["Miranda", "Female", 33, 6])
.addRow(["Miranda", "Female", 33, 6])
.addRow(["Miranda", "Female", 33, 6])
.addRow(["Miranda", "Female", 33, 6])
.addRow(["Miranda", "Female", 33, 6])
.addRow(["Miranda", "Female", 33, 6])
.build();
var tableChart = Charts.newTableChart().setDataTable(data);
//tableChart.setDimensions(1200, 100); // Uncomment this line if you wish to set dimentions in pixels.
tableChart.setOption('width', '100%');
tableChart.setOption('height', '100%');
app.add(tableChart.build());
return app;
}