无法使用应用脚本向Google表格中的图表添加注释 [英] Unable to add annotations to charts within google sheets using app script

查看:120
本文介绍了无法使用应用脚本向Google表格中的图表添加注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Google工作表中的数据,使用Google App脚本创建折线图和面积图png图像.我能够成功创建图形,但是无法在可以使用Java脚本添加的应用程序脚本中添加注释字段.

I am trying to create line and area chart png images with google app scripts using data within a google sheet. I am able to successfully create the graphs, but unable to add an annotation field in app scripts that can be added using java script.

以下是应用程序脚本代码,我希望能够添加.addColumn(Charts.ColumnType.STRING, "annotationText").addColumn({type: 'string', role: 'annotation'})之类的内容,就像在javascript中完成的一样.以下代码均无效,并且似乎无法通过Google脚本声明将列分配给注释"角色.是否有一些未公开的方法通过Google脚本向图表添加注释?我找不到使用google脚本将注释角色分配给列的任何文档,但是看来这是可能的.有谁知道如何通过谷歌脚本做到这一点?

Below is the app script code, I would expect I'd be able to add something like .addColumn(Charts.ColumnType.STRING, "annotationText") or .addColumn({type: 'string', role: 'annotation'}) like is done within javascript. Neither work in the code below, and there seems to be no way to declare via google script that a column is assigned to the "annotation" role. Is there some undocumented way to add annotations to charts via google scripts? I could not find any documentation for assigning annotation roles to columns using google script, but it seems that this would be possible. Does anyone know how to do this via google scripts?

var data = Charts.newDataTable()
       .addColumn(Charts.ColumnType.STRING, "Month")
       .addColumn(Charts.ColumnType.NUMBER, "In Store")
       .addColumn(Charts.ColumnType.NUMBER, "Online")
       .addColumn(Charts.ColumnType.STRING, "annotationText")
       .addRow(["January", 10, 1, "cold!"])
       .addRow(["February", 12, 1,""])
       .addRow(["March", 20, 2, ""])
       .addRow(["April", 25, 3, "showers"])
       .addRow(["May", 30, 4,""])
       .build();

   var chartBlob = Charts.newAreaChart()
       .setDataTable(data)
       .setStacked()
       .setRange(0, 40)
       .setTitle("Sales per Month")
       .build()
       .getAs('image/PNG');

推荐答案

Charts Service公开了Google Visualization API的有限部分.例如,不支持注释.

The Charts Service exposes a limited portion of the Google Visualization API. Annotations are not supported, for example.

如果您将客户端javascript(例如,在对话框中)与Visualization API一起使用,则可以添加注释.不幸的是,这不适合您的另存为图像"方法.

You can add annotations if you use client-side javascript (in a dialog, for example) with the Visualization API. Unfortunately, that would not fit your save-as-image approach.

这篇关于无法使用应用脚本向Google表格中的图表添加注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆