Reputation: 125
I have a Google Sheets spreadsheet with a chart. I'd like to customize the chart colors beyond what is available in the default color palette. I believe this should be possible with Apps Scripts. But I cannot get the following to work for a Line Chart:
function chartColors() {
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:I100")
var chart = sheet.getCharts()[0];
chart = chart.modify()
.setOption('colors', ['red', 'blue', 'green', 'black'])
.build();
sheet.updateChart(chart);
};
Here is the example I am trying to follow: https://developers.google.com/apps-script/reference/spreadsheet/embedded-chart
I was able to Update Title, but the colors aren't working for some reason.
Suggestions?
Upvotes: 2
Views: 3936
Reputation: 125
The above script works. My question was based on an implementation error on my end (wrong index value). Thanks to Jack Brown for commenting and confirming.
Leaving this questions here in case the above helps others add custom chart coloring to Google Sheets Charts.
Upvotes: 2