我正在使用Google脚本并在电子表格中创建图表,但是现在已经有几天了,我认为这归因于我对google脚本及其嵌入式图表对象使用的语法缺乏理解。
根据我的理解,语法如下:
要将烛台的上升颜色设置为绿色,我会这样做:
.setOption('candlestick', {risingColor: {fill: '#31d831'}})
但是这不起作用!我认为语法是这样的:
candlestick.risingColor.fill
└────┬────┘ └────┬────┘ └──┴──────────────┐
└───────┐ └──────────┐ │
.setOption('candlestick', {risingColor: {fill: '#31d831'}})
我做这个假设是因为这里的代码可以正常工作
.setOption('vAxes', {0: {viewWindow: {min: 1}}})
其文档类似
vAxis.viewWindow.min
└─┬─┘ └────────┬┘└─┴───────────────────┐
└──────────┐ └──────────┐ │
.setOption('vAxes', {0: {viewWindow: {min: 1}}})
|
┌────────────────────┴──────────────────────────────┐
This zero refers to the data set I would like to edit
在键入此内容时,我还意识到我将Axis
拼写为Axes
错了,但这仍然有效即使在文档中也提到Axis
我非常困惑,我无法在任何地方找到答案,我的google-fu可能很弱,但我无法弄清楚。
This is a similar question however they are not using embedded sheets,即使我复制其语法也不起作用!
在此先感谢您的帮助!
编辑: 这是我用来生成图表的代码:
var chart = data.newChart()
.setChartType(Charts.ChartType.CANDLESTICK)
.addRange(candle.getRange("a:e"))
.setOption('vAxes', {0: {viewWindow: {min: smallestValue-1, max: largestValue+1}}})
.setOption('candlestick', {risingColor: {stroke: '#31d831'}, fallingColor: {stroke: '#d83131', fill: '#ffffff'}}) // This is the line that doesn't work because I am unsure of the syntax!
.setOption('height', 735)
.setOption('width', 1175)
.setPosition(1, 1, 0, 0)
.build()
candle.insertChart(chart)
此语法与second answer中possible duplicate中的语法不同。 可能重复的accepted answer要求用户使用Google表格中的图表GUI创建图表后,导出图表并从中获取选项。但是,您不能在Google表格GUI中编辑烛台图表的颜色! 我知道烛台图表可以着色,因为example in the documentation可以着色(如我原始问题中所述,在使用.setOption()时,此语法不起作用)
我也尝试过在this question中看到的这种语法:
var chart = data.newChart()
.setChartType(Charts.ChartType.CANDLESTICK)
.addRange(candle.getRange("a:e"))
.setOption('vAxes', {0: {viewWindow: {min: smallestValue-1, max: largestValue+1}}})
.setOption('candlestick.risingColor.stroke', '#31d831')
.setOption('candlestick.fallingColor.stroke', '#d83131')
.setOption('candlestick.fallingColor.fill', '#ffffff')
.setOption('height', 735)
.setOption('width', 1175)
.setPosition(1, 1, 0, 0)
.build()
candle.insertChart(chart)
但是这也不起作用
其他任何人的最终编辑: 我得出的结论是,不可能做我想做的事情,在TheMaster的帮助下,他指出了我的使用方向,taking advantage of the sidebar我将此添加为编辑而不是答案,因为有一天可能会出现这种情况,如果可以的话,最好能得到正确的答案。
祝将来有其他人对此感到高兴,让我随时了解它的可能性!