'Change bar chart series color using Google Apps Script, EmbeddedChart

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.



Solution 1:[1]

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?

Solution 2:[2]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Boris
Solution 2 ale13