Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
858 views
in Technique[技术] by (71.8m points)

google apps script - Chart modify() gives error Exception: Those columns are out of bounds

I started re-using a script attached to a spreadsheet that I made a few years ago. If I remember right, it was working fine but it now throws the error: Exception: Those columns are out of bounds. The script changes the several options on each chart that was saved to their own page. I can't see how if it's saved to it's own page it has columns. I tried .setPosition() which locked up the charts so that they can't load. I found that under embedded charts and I'm not sure if a chart that is given its own sheet? is considered embedded. My code is below if anyone can help.

Here is a copy of the sheets

Thanks Jamie

function GM3_modifyAllCharts() {
 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheets1 = ss.getActiveSheet();
 var sheets2 = ss.getSheets();
 for (i = 2; i < (sheets2.length - 6); i++) {
    var shtLabel= ss.getSheetByName("Graph Labels");
    var range = shtLabel.getRange((i-1),1);
    Logger.log(range.getValues());
    var bayValues = range.getValues();
    var range = shtLabel.getRange((i-1),2);
    Logger.log(range.getValues());
    var cropValues = range.getValues();
    var shtData= ss.getSheetByName("GM Data");
    var range = shtData.getRange(1,2);
   Logger.log(range.getValues());
    var dateValues = range.getValues();
    var formattedDate1 = " 1 "; //Utilities.formatDate(new Date(dateValues), "GMT+4", "M-d-yy");
    var formattedDate2 = " 2 "; //Utilities.formatDate(new Date(dateValues), "GMT+4", "D");
    var sheet2 = SpreadsheetApp.setActiveSheet(ss.getSheets()[i]);
    var chart = sheet2.getCharts()[0];
    Logger.log(sheet2.getName()); 

    chart = chart.modify()
   .setOption('titleTextStyle', {color: '#273746  ', fontSize: 14})
    .setOption('title', 'Sw '+ (i-1)+'   '+ bayValues + '   '+ cropValues)
    .setOption('subtitleTextStyle', {color: '#273746  ', fontSize: 14})
    .setOption('subtitle','Date: '+ formattedDate1+'   Julian: '+ formattedDate2)
    .build();

    sheet2.updateChart(chart); // <<<< Here is where the error happens.
  }
}
question from:https://stackoverflow.com/questions/65942512/chart-modify-gives-error-exception-those-columns-are-out-of-bounds

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Issue

It seems that the sheets containing the charts are of OBJECT type which means we have limited access to editing it to the way you want it. I also tried and replicated how you do it on your end and it resulted to the same error/issue.

Suggestions

I tried moving/copying your charts to another sheet and it seems that I can freely and easily edit it on the new sheet. What I can suggest is to move your charts to another sheet(new or existing) and use it when modifying your charts moving forward.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...