【问题标题】:Change bar chart series color using Google Apps Script, EmbeddedChart使用 Google Apps Script、EmbeddedChart 更改条形图系列颜色
【发布时间】:2021-05-04 07:18:39
【问题描述】:

我在 Google 工作表中嵌入了条形图。我想使用 Google Apps 脚本更改条形的颜色。我试过了

  var charts = sheet.getCharts();
  var chart = charts[0];
  chart = chart.modify()
    .setOption('title', 'New Title')
    .setOption('series.0.color', 'red')
    .build();
  sheet.updateChart(chart);

标题会更新,但颜色不会。 我也试过.setColors(),也没有效果。 当构建一个新的图表(newChart())时 .setOption('series.0.color', 'red'),使用指定颜色。

【问题讨论】:

  • 您要创建哪种类型的图表?你也可以分享图表的创建吗?您使用的是 Apps 脚本还是 Visualization API? @鲍里斯
  • @ale13 这是一个条形图。使用 Apps 脚本。

标签: google-apps-script google-visualization bar-chart


【解决方案1】:

This article给了我一个线索

使用符号.setOption('series', {0: {color: 'red'}}) 成功了!

是否有原因原始符号不适用于修改,仅用于创建?这是我应该报告的错误吗?

【讨论】:

  • 最近,我在关注这个问题(this answer)。我发现setOption() 方法here 允许使用哪些选项。没有series.0.color 样式选项。所以我不知道为什么允许创建series.0.color 样式选项。我已经得出结论,EmbeddedChart 和普通的 Chart 是不一样的。
【解决方案2】:

Google 的问题跟踪器 here 似乎已报告了此问题

我建议您为该问题加注星标,以获取与之相关的任何更新。

【讨论】:

  • 谢谢你,ale13!
猜你喜欢
  • 1970-01-01
  • 2015-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-03
  • 2012-01-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多