I want to dynamically add ranges to a new EmbeddedChartBuilder but I’m getting this error:
“in dashOutput – line: 605, error: InternalError: Cannot find method insertChart($Proxy843).”
Here is code that is not dynamic but works:
var tRange = sourceSheet.getRange(12, 1, 4, 2);
var tRange2 = sourceSheet.getRange(12,3,4,2);
var chart2 = destSheet.newChart()
.setPosition(5,6,5,5)
.setChartType(Charts.ChartType.LINE)
.addRange(tRange)
.addRange(tRange2)
.build();
destSheet.insertChart(chart2);
But this gives me that error.
var tRange = sourceSheet.getRange(12, 1, 4, 2);
var tRange2 = sourceSheet.getRange(12,3,4,2);
var chart2 = destSheet.newChart()
.setPosition(5,6,5,5)
.setChartType(Charts.ChartType.LINE);
chart2.addRange(tRange);
chart2.addRange(tRange2);
chart2.build();
destSheet.insertChart(chart2);
The second example isn’t dynamic but if it worked, I would repeat .addRange() inside of a loop.
Any ideas? What am I missing? Do you really have to know how many ranges you are going to add at time of chart creation?
Thanks,
Eric B.
The problem is that the Sheet.newChart method creates an instance of the EmbeddedChartBuilder class, the EmbeddedChartBuilder.build method creates an instance of the EmbeddedChart class and the Sheet.insertChart method requires the
EmbeddedChartinstance. In 1st code thechart2variable is instance of theEmbeddedChartclass and in the 2nd case thechart2variable is instance of theEmbeddedChartBuilderclass. That is why the error takes place. Change the code as following. It should work.