I'm looking to overwrite chart1
with the options from chart2
. I've tried to extract the options from chart2 using chart.getOptions()
, but I can't seem to set those options to chart1.
Ideally every option would be copied over:
- All Format
- Reference Range
- Etc.
Code Sample:
function overwriteChartOptions(chart1, chart2) {
var options = chart2.getOptions();
var chart1 = chart1.modify()
.setOption(options)
.build();
sheet1.updateChart(chart1);
}
overwriteChartOptions(sheet.getCharts()[0], sheet.getCharts()[1])
Error Message:
Exception: The parameters (String) don't match the method signature for SpreadsheetApp.EmbeddedChartBuilder.setOption.
I've attempted to extract each and every option individually, but I wasn't able to find the documentation where app scripts listed that. All I was able to find is this and it doesn't contain a list of all of the option:
- https://developers.google.com/apps-script/reference/charts/chart-options
- https://developers.google.com/chart/interactive/docs/customizing_charts
I've looked at alternative methods of overwriting a chart with another with methods like Sheets.Spreadsheets.batchUpdate(), but couldn't figure it out.
Is there a way to copy all options from one chart to another?
Edit:
I've tried changing .setOption(options)
to .setOptions(options)
, but received this error:
TypeError: chartBuilder.addRange(...).setChartType(...).setOptions is not a function