Skip to content

Instantly share code, notes, and snippets.

@mhawksey
Created July 28, 2015 21:38
Show Gist options
  • Save mhawksey/b2298fcd3088698ac33b to your computer and use it in GitHub Desktop.
Save mhawksey/b2298fcd3088698ac33b to your computer and use it in GitHub Desktop.
// Modified from http://stackoverflow.com/a/22200230/1027723
function emailCharts(sheet,emails,emailSubject){
var charts = sheet.getCharts();
if(charts.length==0){
MailApp.sendEmail({
to: emails,
subject: "ERROR:"+emailSubject,
htmlBody: "No charts in the spreadsheet"});
return;
}
var chartBlobs=new Array(charts.length);
var emailBody="Charts<br>";
var emailImages={};
for(var i=0;i<charts.length;i++){
var builder = charts[i].modify();
builder.setOption('vAxis.format', '#');
var newchart = builder.build();
chartBlobs[i]= newchart.getAs('image/png');
emailBody= emailBody + "<p align='center'><img src='cid:chart"+i+"'></p>";
emailImages["chart"+i]= chartBlobs[i];
}
MailApp.sendEmail({
to: emails,
subject: emailSubject,
htmlBody: emailBody,
inlineImages:emailImages});
}
@akkisapra
Copy link

Hi @mshawksey,
I read your article on https://mashe.hawksey.info/2015/07/tips-on-emailing-inline-google-charts-from-sheets-using-apps-script/
I am looking to mail my google chart. but i could not. Can you please help me on understanding your logic and how to use it ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment