Error inserting chart in google sheet -
i have following code allows me create bar chart
var chart = charts.newbarchart() .setdatatable(datatable) .settitle("rain per month"); sheet.insertchart(chart.build());
unfortunately, error saying "cannot find method insertchart(chart)".
it seems sheet.insertchart function must take embeddedchart.
how can turn chart embedded chart insertchart function take it?
regards crouz
the methods using adding charts uiapp. add chart google sheet use syntax:
var chart = sheet.newchart() .setcharttype(charts.charttype.bar) .addrange(sheet.getrange("a1:b4")) .setposition(5, 5, 0, 0) .setoption("title", "dynamic chart") .build(); sheet.insertchart(chart);
this code taken here on google app scripts documentation.
also, datatable class used create charts when adding charts html or uiapp. if wanted add chart spreadsheet if user had clicked insert > chart, have use getrange
draw data. if you're drawing data multiple sources suggest combining data , adding somewhere in spreadsheet using sheet.getrange().setvalue()
.
if wanted draw data seperate google spreadsheet this:
//spreadsheetapp.openbyurl.openbyid(inset appropriate id here) work var externalsheets = spreadsheetapp.openbyurl(insert appropriate url here).getsheets(); var chart = sheet.newchart() .setcharttype(charts.charttype.bar) .addrange(sheets[insert appropriate sheet index here].getrange("a1:b4")) .setposition(5, 5, 0, 0) .setoption("title", "dynamic chart") .build(); sheet.insertchart(chart);
Comments
Post a Comment