在脚本中创建图表的入口点。
以下示例创建了一个基本的数据表格,并使用数据填充了面积图,然后将其作为图片添加到网页中:
function doGet() { const data = Charts.newDataTable() .addColumn(Charts.ColumnType.STRING, 'Month') .addColumn(Charts.ColumnType.NUMBER, 'In Store') .addColumn(Charts.ColumnType.NUMBER, 'Online') .addRow(['January', 10, 1]) .addRow(['February', 12, 1]) .addRow(['March', 20, 2]) .addRow(['April', 25, 3]) .addRow(['May', 30, 4]) .build(); const chart = Charts.newAreaChart() .setDataTable(data) .setStacked() .setRange(0, 40) .setTitle('Sales per Month') .build(); const htmlOutput = HtmlService.createHtmlOutput().setTitle('My Chart'); const imageData = Utilities.base64Encode(chart.getAs('image/png').getBytes()); const imageUrl = `data:image/png;base64,${encodeURI(imageData)}`; htmlOutput.append('Render chart server side: <br/>'); htmlOutput.append(`<img border="1" src="${imageUrl}">`); return htmlOutput; }
属性
| 属性 | 类型 | 说明 | 
|---|---|---|
| Chart | Chart | 枚举了来源中隐藏维度在图表中的表示方式。 | 
| Chart | Chart | 枚举了来源中多个范围在图表中的表示方式。 | 
| Chart | Chart | Charts 服务支持的图表类型的枚举。 | 
| Column | Column | Data中列的有效数据类型的枚举。 | 
| Curve | Curve | 图表中曲线的样式枚举。 | 
| Point | Point | 线条中点的样式的枚举。 | 
| Position | Position | 图表中图例位置的枚举。 | 
方法
| 方法 | 返回类型 | 简介 | 
|---|---|---|
| new | Area | 开始构建面积图,如 Google 图表工具文档中所述。 | 
| new | Bar | 开始构建条形图,如 Google 图表工具文档中所述。 | 
| new | Column | 开始构建柱形图,如 Google 图表工具文档中所述。 | 
| new | Data | 创建一个空数据表,其值可以手动设置。 | 
| new | Data | 创建新的“数据视图”定义。 | 
| new | Line | 开始构建折线图,如 Google 图表工具文档中所述。 | 
| new | Pie | 开始构建饼图,如 Google 图表工具文档中所述。 | 
| new | Scatter | 开始构建散点图,如 Google 图表工具文档中所述。 | 
| new | Table | 开始构建表格图表,如 Google 图表工具文档中所述。 | 
| new | Text | 创建新的文本样式构建器。 | 
详细文档
new
new
new
new
new
创建新的“数据视图”定义。
使用 setter 定义数据视图的不同属性。
返回
Data - DataViewDefinitionBuilder,可用于构建数据视图定义。