首页 > 解决方案 > 在 Google Apps 脚本中更改图表边框颜色

问题描述

我正在使用 Google Apps 脚本,并且正在通过脚本将图表插入到我的工作表中。我注意到在使用宏记录图表的创建时,并非图表的所有属性都被记录下来。

例如,我录制了一个宏,并将图表的背景设置为透明(或任何颜色),然后当我运行该宏时,背景会恢复为标准白色。

我可以通过将其设置在下面来修复背景颜色.setOptions(请参见下面的代码),但我似乎无法弄清楚如何更改边框的颜色(真的我想摆脱它)。

  chart = sheet.getSheetByName("Sheet1").newChart()
    .asLineChart()
    .addRange(sheet.getSheetByName("ForGraphs").getRange(1, 1, 22, team_names.length + 1))
    .setMergeStrategy(Charts.ChartMergeStrategy.MERGE_COLUMNS)
    .setTransposeRowsAndColumns(false)
    .setNumHeaders(-1)
    .setHiddenDimensionStrategy(Charts.ChartHiddenDimensionStrategy.IGNORE_BOTH)
    .setOption('backgroundColor.fill', "#0000ffff")
    .setOption('bubble.stroke', '#000000')
    .setOption('useFirstColumnAsDomain', true)
    .setOption('focusTarget', 'category')
    .setOption('curveType', 'none')
    .setOption('legend.position', 'top')
    .setOption('annotations.domain.textStyle.color', '#808080')
    .setOption('textStyle.color', '#000000')
    .setOption('legend.textStyle.color', '#1a1a1a')
    .setOption('subtitleTextStyle.color', '#999999')
    .setOption('titleTextStyle.color', '#757575')
    .setOption('annotations.total.textStyle.color', '#808080')
    .setOption('hAxis.slantedText', true)
    .setOption('hAxis.slantedTextAngle', 0)
    .setOption('hAxis.textStyle.color', '#000000')
    .setOption('hAxis.titleTextStyle.color', '#000000')
    .setOption('vAxes.0.minorGridlines.count', 5)
    .setOption('vAxes.0.minorGridlines.color', '#f3f3f3')
    .setOption('vAxes.0.textStyle.color', '#000000')
    .setOption('vAxes.0.titleTextStyle.color', '#000000')
    .setOption('height', 322)
    .setOption('width', 659)
    .setPosition(26, 5, 2, 16)
    .build();

我已手动将其添加.setOption('backgroundColor', "#0000ffff")到此块中。

我在谷歌的官方文档中看到他们说该backgroundColor.fill选项可以将对象作为输入,但他们忽略了他们反对的样子。我会认为这将是带有.strokeand的东西.strokeWeight,但这似乎不起作用。

非常感谢!

标签: google-apps-scriptgoogle-sheetscharts

解决方案


这意味着您可以通过设置setOption('backgroundcolor', 'white')setOption('backgroundcolor', {fill:'white'})

根据该文件,不支持进一步的背景选项


线条颜色由setOptions('colors', ['blue', 'red'])


图表区域背景颜色由chartArea.backgroundColor

文件中对此进行了说明。


推荐阅读