Can I access charts already within a spreadsheet via GAS? I had to implement a workaround whilst this was being developed and now would like to be able to grab the chart from a sheet and mail it as an attachment.
Wonderful and so easy to use scripts for Charts. Thanks. Really, a nice piece of code, and still nicer way to present and explain it.
By the way, I searched here for Romain Vialard who wrote Embedding Google DocList in Google Site on Tutorial Page. But, as I couldn't find him, I am making my comment here.
Actually, there is some spelling mistakes in the word 'attachements' and that generates an error in Script Editor while testing the code. The code snippet is:
var attachments = page.getAttachements(); for(i in attachements){
attachements[i].deleteAttachment(); }.This took me a while to find the mistakes, and I hope others won't have to, once corrected. Thank you once againg for nice charts in website, email attachment and Docs.
You can send more than one Charts by simply placing an arrays of charts after 'attachements:'. For example,
MailApp.sendEmail('[email protected]','Two Charts', 'Yes, TWO Charts can be sent!!!',{attachments: [chart1,chart2]});
Try using the following code, replacing '[email protected]' with your real email address. You are certainly going to receive two charts attached with the email. The code is:
function sendMoreCharts(){
var dataTable1=Charts.newDataTable() .addColumn(Charts.ColumnType.STRING, 'Students') .addColumn(Charts.ColumnType.NUMBER, 'Math') .addColumn(Charts.ColumnType.NUMBER, 'Computer') .addRow(['John',75,80]) .addRow(['Rahul',65,85]) .addRow(['Suleman',90,70]) .build() var chart1=Charts.newColumnChart() .setDataTable(dataTable1) .setColors(['red','green']) .setXAxisTitle('Students') .setYAxisTitle('Scores') .setTitle('FIRST TEST') .build(); var dataTable2=Charts.newDataTable() .addColumn(Charts.ColumnType.STRING, 'Students') .addColumn(Charts.ColumnType.NUMBER, 'Math') .addColumn(Charts.ColumnType.NUMBER, 'Computer') .addRow(['John',75,80]) .addRow(['Rahul',65,85]) .addRow(['Suleman',90,70]) .build(); var chart2=Charts.newColumnChart() .setDataTable(dataTable2) .setColors(['black','gray']) .setBackgroundColor('#EEEEFF') .setXAxisTitle('Students') .setYAxisTitle('Scores') .setTitle('SECOND TEST') .build(); MailApp.sendEmail('[email protected]', 'attach two files', 'See if Two files received', {attachments:[chart1,chart2]}); }
Perfect post. Here’s a tool that lets youbuild all types of online reporting with graphs and charts for sales, marketing, finance, HR, support, etc. http://blog.caspio.com/web_apps/how-to-add-dynamic-data-charts-and-graphs-to-your-web-apps/
23 comments :
That's great!
Can I access charts already within a spreadsheet via GAS? I had to implement a workaround whilst this was being developed and now would like to be able to grab the chart from a sheet and mail it as an attachment.
Hi TC,
You can't do that as part of our initial release, but this is a feature we're working hard on adding!
Hi TC,
You can't do that as part of our initial release, but this is a feature we're working hard on adding!
Wonderful and so easy to use scripts for Charts. Thanks. Really, a nice piece of code, and still nicer way to present and explain it.
By the way, I searched here for Romain Vialard who wrote Embedding Google DocList in Google Site on Tutorial Page. But, as I couldn't find him, I am making my comment here.
Actually, there is some spelling mistakes in the word 'attachements' and that generates an error in Script Editor while testing the code. The code snippet is:
var attachments = page.getAttachements();
for(i in attachements){
attachements[i].deleteAttachment();
}.This took me a while to find the mistakes, and I hope others won't have to, once corrected.
Thank you once againg for nice charts in website, email attachment and Docs.
This really is great. But how do you send two charts (or more) via email?
How do you attach two charts in one email? Thanks!
You can send more than one Charts by simply placing an arrays of charts after 'attachements:'. For example,
MailApp.sendEmail('[email protected]','Two Charts', 'Yes, TWO Charts can be sent!!!',{attachments: [chart1,chart2]});
Try using the following code, replacing '[email protected]' with your real email address.
You are certainly going to receive two charts attached with the email.
The code is:
function sendMoreCharts(){
var dataTable1=Charts.newDataTable()
.addColumn(Charts.ColumnType.STRING, 'Students')
.addColumn(Charts.ColumnType.NUMBER, 'Math')
.addColumn(Charts.ColumnType.NUMBER, 'Computer')
.addRow(['John',75,80])
.addRow(['Rahul',65,85])
.addRow(['Suleman',90,70])
.build()
var chart1=Charts.newColumnChart()
.setDataTable(dataTable1)
.setColors(['red','green'])
.setXAxisTitle('Students')
.setYAxisTitle('Scores')
.setTitle('FIRST TEST')
.build();
var dataTable2=Charts.newDataTable()
.addColumn(Charts.ColumnType.STRING, 'Students')
.addColumn(Charts.ColumnType.NUMBER, 'Math')
.addColumn(Charts.ColumnType.NUMBER, 'Computer')
.addRow(['John',75,80])
.addRow(['Rahul',65,85])
.addRow(['Suleman',90,70])
.build();
var chart2=Charts.newColumnChart()
.setDataTable(dataTable2)
.setColors(['black','gray'])
.setBackgroundColor('#EEEEFF')
.setXAxisTitle('Students')
.setYAxisTitle('Scores')
.setTitle('SECOND TEST')
.build();
MailApp.sendEmail('[email protected]',
'attach two files', 'See if Two files received',
{attachments:[chart1,chart2]});
}
To send more charts in atachments, you have to use this format in MailApp arg >>>
attachments:[chart1,chart2]
where chart1,chart2 are the charts you created with apps. Also, you can create five charts and try sending them all like this.
How do you send charts as pdf via email?
Thanks!!
Hi Faku,
Simply call "getAs" on the chart before mailing it out. Example:
var pdfChart =
chart.getAs("application/pdf")
.setName("Chart PDF.pdf");
MailApp.sendEmail('[email protected]',
'attach PDF', 'See attached',
{attachments:[pdfChart]});
Hi Guga,
Thanks a lot!!
Es exactly what we needed. =)
Great !!!
Are "Candlestick Charts" planned to be available in GAS ?
IF so, any idea of the schedule ?
Thanks
It's posible set the legend font and set column width in column chart??
Thanks!!
Hi Anonymous,
Candlestick charts aren't planned right now, but we'll be adding more charts in the future, stay tuned.
Faku, we'll be allowing you to configure more options (including the legend font) soon.
I'm writing down all of these suggestions, so please keep them coming!
Hi, Guga:
Is it possible to insert a chart into google spreadsheet by GAS(not by the chart gadgets of spreadsheet)?
It's not currently possible to insert a chart into a Spreadsheet directly through GAS, but we're actively working on it!
Hi, How can I see the chart with my Android platform. I just get a suite of numbers but no chart.
Any idea ?
Perfect post. Here’s a tool that lets youbuild all types of online reporting with graphs and charts for sales, marketing, finance, HR, support, etc. http://blog.caspio.com/web_apps/how-to-add-dynamic-data-charts-and-graphs-to-your-web-apps/
I am using GWT and Gchart to render the images , Can I use the above api's to save those images to a doc file?
Hi Smitha,
Yes, Charts will absolutely work in documents. Here's an example:
function myFunction() {
var table = Charts.newDataTable()
.addColumn(Charts.ColumnType.STRING, "color")
.addColumn(Charts.ColumnType.NUMBER, "blue")
.addColumn(Charts.ColumnType.NUMBER, "green")
.addColumn(Charts.ColumnType.NUMBER, "red")
.addColumn(Charts.ColumnType.NUMBER, "yellow")
.addRow(["votes", 5, 3, 2, 1])
var chart = Charts.newColumnChart()
.setDataTable(table)
.setColors(["blue", "green", "red", "yellow"])
.build();
var doc = DocumentApp.openById("");
doc.appendImage(chart);
}
This is fantastic work!
Any idea what the timeline for adding combo charts to this is?
Hi
I have a google site page and inserted this script so I can add a chart. However I keep getting this error:
"Another entity already exists with the same name."
on the line:
page.addHostedAttachment(chart, "Income Chart");
Any idea on how to fix this?
Cheers
David
Gustavo, Hi!
Do you know what about issue 2351 on you tracker?
http://code.google.com/p/google-apps-script-issues/issues/detail?id=2351
Would you please give us any forecast?
Post a Comment