Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using EmbeddedChartBuilder and 'getting columns are out of bounds'

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

like image 801
wild Avatar asked Jun 19 '12 04:06

wild


1 Answers

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.

like image 164
Serge insas Avatar answered Nov 06 '22 04:11

Serge insas