0
votes

I have an embedded bar chart in a Google sheet. I'd like to change the color of the bars using Google Apps Script. I tried

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

The title gets updated, but the color does not. I also tried .setColors(), with no effect either. When a build a new chart (newChart()) with the same .setOption('series.0.color', 'red'), the specified color is used.

2
Which type of chart are you creating? Can you share the creation of the chart as well? Are you using Apps Script or the Visualization API? @Borisale13
@ale13 It's a bar chart. Using Apps Script.Boris

2 Answers

3
votes

This article gave me a clue

Using the notation .setOption('series', {0: {color: 'red'}}) did the trick!

Is there a reason the original notation doesn't work for modify, only for create? Is that a bug that I should report?

1
votes

It looks like this has been reported on Google's Issue Tracker here

I suggest you star the issue in order to get any updates related to it.