This is my short function that keeps getting "Those columns are out of bounds"
function myFunction() {
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getDataRange();
var chartBuilder = sheet.newChart();
chartBuilder.addRange(range).setChartType(Charts.ChartType.LINE).setOption('title', 'My Line Chart!');
sheet.insertChart(chartBuilder.build());
}
I've tried sheet.getRange("A1:B6")
as well.
The 1st column are dates and the 2nd column are ints. The standard Insert a Graph GUI can use the data as is.
Has anybody had any success with the new EmbeddedGraph classes? thanks
The problem is not the input data range, but where the chart is being placed in the build process. It's attempting to put the chart on top of the data on the page. You need to use setPosition
on the chartBuilder
to tell where the chart should go. I believe it will try to put it at row 1, column 1 if you don't specify anything, which means it's likely trying to overwrite your data.
Try replacing your last line with this
sheet.insertChart(chartBuilder.setPosition(7, 1, 1, 1).build());
setPosition parameters are: int Row, int Col, Row offset, Col offset.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With