Whenever I've looked into how to email a chart, all the answers involve some variation on using the getAs function to save the chart as an image and then either inlining it or attaching it to the email. But I'm struggling to save the chart as an image in order to attach it. When I run the following code:
var chart = demandLastWeekSheet.getCharts().getAs("image/png");
I get this error:
TypeError: demandLastWeekSheet.getCharts(...).getAs is not a function (line 8, file "Code")
In fact, I get the same error if I try.getBlob(), .modify() or any other functions from here: https://developers.google.com/apps-script/reference/spreadsheet/embedded-chart.html
Surely these functions have not been deprecated? Am I doing something wrong/stupid? New to the world of apps script, any pointers welcome, Sorry also if this is a badly phrased question: also I am new to stack overflow :)
Any suggestions??
getCharts()
returns EmbeddedChart[]
. In your script, the method of getAs
is used for an array. I think that this is the reason of your issue. In order to retrieve the blob of the chart using the method of getAs
, please modify as follows.
var chart = demandLastWeekSheet.getCharts().getAs("image/png");
var chart = demandLastWeekSheet.getCharts()[0].getAs("image/png");
demandLastWeekSheet
is retrieved. If you want to retrieve the 2nd chart, please modify from [0]
to [1]
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.