I'm trying to follow the instructions from this post: How to dynamically adjust a Google Sheets chart vertical (y) axis minimum and maximum value to data set? but I'm getting an access exception. I've added a test to verify that I can access cells on the sheet and that works but the call to updateChart(chart) fails saying:
Exception: Service Spreadsheets failed while accessing document with id <my sheet's iD>. at updateChart(Code:14:9)
The "Hello" and values for min/max do correctly appear in D46:D48. I have no known (to me) permissions set on the sheet or on any ranges within.
Any idea why I'm getting this exception?
function updateChart(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('NetWorth Dashboard');
sheet.getRange('d46').setValue("HELLO");
var nw_max = sheet.getRange("nw_dev_chart_max").getValue();
var nw_min = sheet.getRange("nw_dev_chart_min").getValue();
sheet.getRange('d47').setValue(nw_min);
sheet.getRange('d48').setValue(nw_max);
var chart = sheet.getCharts()[0];
chart = chart.modify()
.setOption('vAxes.0.viewWindow.max', nw_max)
.setOption('vAxes.0.viewWindow.min', nw_min)
.build();
sheet.updateChart(chart);
}
I reverted the script's setOption lines and created an example spreadsheet: #gid=906716897