Google Apps脚本:如何设置“使用列A作为标签”嵌入在电子表格中的图表中? [英] Google Apps Script: How to set "Use column A as labels" in chart embedded in spreadsheet?

查看:92
本文介绍了Google Apps脚本:如何设置“使用列A作为标签”嵌入在电子表格中的图表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Google Apps脚本和 EmbeddedChartBuilder 在我的Google电子表格中嵌入了折线图。当您手动创建这些图表时,您具有使用列A作为标签(其中A是数据范围中的第一列)的(非默认)选项。我无法从脚本中找到相同的方法。从 Google可视化折线图文档看来,默认情况下将第一列视为具有域角色;但EmbeddedChartBuilder似乎覆盖了这一点,并为所有列提供数据角色。由于我没有明确的DataTable,我无法设置列角色我自己。

I am using Google Apps Script and EmbeddedChartBuilder to embed line charts within my Google Spreadsheet. When you create these charts by hand, you have the (non-default) option to "Use column A as labels" (where "A" is the first column in the data range). I cannot find a way to do the same from a script. From the Google Visualization Line Chart documentation, it appears that the default is to treat the first column as having the "domain" role; but EmbeddedChartBuilder seems to override this and give all columns the "data" role. Since I don't have an explicit DataTable, I have no way to set the column roles myself.

我错过了这样做的方式吗?或者,我是否必须将方法从EmbeddedChartBuilder切换到使用电子表格作为数据源的

Have I missed a way to do this? Or do I have to switch approaches from EmbeddedChartBuilder to using the spreadsheet as a data source?

推荐答案

发现它!使用将选项 useFirstColumnAsDomain 设置为 true script / class_embeddedchartbuilder#setOptionrel =nofollow noreferrer> EmbeddedChartBuilder.setOption

Found it! Set the option useFirstColumnAsDomain to true with EmbeddedChartBuilder.setOption.

这个选项似乎没有记录。我通过转到发布图表(点击图表,然后从右上角的下拉列表中选择)并检查给定代码中的JavaScript数据结构来找到它。确切地说,我创建了一个图表,其中使用列A作为标签未选中,抓取发布数据结构,然后选中使用列A作为标签,抓取新的发布数据结构,并比较两者。为了进行比较,我建议标准化JSON 并运行 diff 。此技术可用于对图表编辑器中的任何设置进行逆向工程。

This option appears to be undocumented. I found it by going to "Publish chart" (click on the chart, then select from the drop-down in the top right) and inspecting the JavaScript data structure in the given code. To be exact, I created a chart with "Use column A as labels" unchecked, grabbed the publish data structure, then checked "use column A as labels", grabbed the new publish data structure, and compared the two. To compare, I suggest normalizing the JSON and running diff. This technique can be used to reverse-engineer any settings in the chart editor.

这篇关于Google Apps脚本:如何设置“使用列A作为标签”嵌入在电子表格中的图表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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