Hi,

Has anyone experimented with generating chart data on the fly for use with 
Google App Script?  I've been able to successfully generate the necessary 
html and javascript as var html, then pass that along to which 
uses MailApp.sendEmail in Google App script.  The problem with this 
approach is that the html and javascript isn't executed and is ignored.  If 
I look at the original email (with the headers), I see the HTML content, 
but the email is otherwise blank and no chart is visible.

Here's a sample of code:
// Generate HTML Content
function genHTML (val1, val2){
  var htmlbody = "<!DOCTYPE html> <html> <head>";
  htmlbody = htmlbody + "<script type=\"text/javascript\" 
src=\"https://www.gstatic.com/charts/loader.js\";></script>";
  htmlbody = htmlbody + "<script type=\"text/javascript\">";
  htmlbody = htmlbody + "google.charts.load(\'current\', 
{\'packages\':[\'corechart\']});";
  htmlbody = htmlbody + "google.charts.setOnLoadCallback(drawChart);";
  htmlbody = htmlbody + "function drawChart() { ";
  htmlbody = htmlbody + "var data = google.visualization.arrayToDataTable(["
;
  htmlbody = htmlbody + "[\'2-Factor Status\', \'Total\'],";
  htmlbody = htmlbody + "[\'Enabled\', " + val1 + "],";
  htmlbody = htmlbody + "[\'Disabled\'," + val2 + "]]);";
  htmlbody = htmlbody + "      var options = { ";
  htmlbody = htmlbody + "        title: \'Google 2-Factor Status\'};";
  htmlbody = htmlbody + "      var chart = new 
google.visualization.PieChart(document.getElementById(\'piechart\'));";
  htmlbody = htmlbody + "        chart.draw(data, options);}";
  htmlbody = htmlbody + "    </script> </head> <body> <div id=\"piechart\" 
style=\"width: 900px; height: 500px;\"></div> </body> </html>";
  Logger.log(htmlbody);
  return htmlbody;
}

Thanks in advance!

-Kevin

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-visualization-api/a62a8ca9-0efe-4b34-86e5-14712f68ad4c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to