Apps Developer Blog

Information for Google Apps Developers

Visualize Your Data: Charts in Google Apps Script!

September 7, 2011
Share on Google+ Share on Twitter Share on Facebook
Google
Labels: Apps Script , Charts

23 comments :

TC said...

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.

September 7, 2011 at 3:01 PM
gmoura said...

Hi TC,

You can't do that as part of our initial release, but this is a feature we're working hard on adding!

September 7, 2011 at 4:55 PM
gmoura said...

Hi TC,

You can't do that as part of our initial release, but this is a feature we're working hard on adding!

September 7, 2011 at 4:55 PM
Learner said...

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.

September 13, 2011 at 10:18 AM
Anonymous said...

This really is great. But how do you send two charts (or more) via email?

September 13, 2011 at 2:35 PM
Kevin said...

How do you attach two charts in one email? Thanks!

September 13, 2011 at 2:36 PM
Learner said...

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]});
}

September 14, 2011 at 3:19 AM
Learner said...

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.

September 14, 2011 at 4:31 AM
Faku said...

How do you send charts as pdf via email?
Thanks!!

September 20, 2011 at 8:15 AM
Guga said...

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]});

September 20, 2011 at 12:21 PM
Faku said...

Hi Guga,
Thanks a lot!!
Es exactly what we needed. =)

September 20, 2011 at 1:05 PM
Anonymous said...

Great !!!

Are "Candlestick Charts" planned to be available in GAS ?

IF so, any idea of the schedule ?

Thanks

September 28, 2011 at 8:14 AM
Faku said...

It's posible set the legend font and set column width in column chart??

Thanks!!

September 30, 2011 at 8:15 AM
gmoura said...

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!

October 5, 2011 at 8:24 AM
水野洋羽 said...

Hi, Guga:

Is it possible to insert a chart into google spreadsheet by GAS(not by the chart gadgets of spreadsheet)?

October 13, 2011 at 8:24 AM
Guga said...

It's not currently possible to insert a chart into a Spreadsheet directly through GAS, but we're actively working on it!

October 14, 2011 at 10:43 AM
arlejeun said...

Hi, How can I see the chart with my Android platform. I just get a suite of numbers but no chart.

Any idea ?

November 14, 2011 at 8:51 AM
lawtonterri said...

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/

March 14, 2012 at 10:11 PM
Smitha said...

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?

March 15, 2012 at 3:38 AM
gmoura said...

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);
}

March 15, 2012 at 2:45 PM
Konish Dutta said...

This is fantastic work!

Any idea what the timeline for adding combo charts to this is?

June 3, 2013 at 7:49 PM
David Pyle said...

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

June 23, 2013 at 2:11 AM
Дмитрий Иванов said...

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?

July 31, 2013 at 6:52 PM

Post a Comment

  

Labels


  • .NET 3
  • #io15 1
  • Admin SDK 4
  • Administrative APIs 26
  • AdSense 1
  • analytics 4
  • Android 5
  • App Engine 5
  • Apps Script 98
  • Auth 1
  • billing 4
  • Charts 1
  • Chrome OS 1
  • classroom 1
  • Cloud Storage API 1
  • Community 1
  • Developers 5
  • Directory API 1
  • Drive 2
  • Drive SDK 38
  • execution API 1
  • Firebase 1
  • Freemium 1
  • Fusion Tables 2
  • Gadgets 5
  • Gmail APIs 16
  • Google APIs 3
  • Google Apps 3
  • Google Apps Directory API 1
  • Google Apps Marketplace 3
  • Google Apps Script 1
  • Google Calendar API 20
  • Google Contacts API 3
  • Google Data Protocol 7
  • google docs 3
  • Google Docs API 20
  • Google Drive 2
  • Google Forms 4
  • Google I/O 3
  • Google Prediction API 3
  • Google Profiles API 2
  • Google sheets 2
  • Google Sites API 4
  • Google Spreadsheets API 4
  • Google Talk 1
  • Google Tasks API 6
  • Google+ 3
  • googlenew 1
  • Groups 2
  • Guest Post 42
  • ISVs 2
  • java 1
  • JavaScript 3
  • marketing 3
  • Marketplace 47
  • Marketplace ISV Guest 21
  • Migration 1
  • Mobile 1
  • mpstaffpick 1
  • oauth 11
  • OpenID 7
  • PHP 1
  • python 4
  • realtime API 1
  • Resellers 2
  • Ruby 1
  • SaaS 1
  • security 1
  • Staff Picks 2
  • webinar 2


Archive


  •     2015
    • Oct
    • Sep
    • Aug
    • Jul
    • Jun
    • May
    • Apr
    • Mar
    • Feb
  •     2014
    • Dec
    • Oct
    • Sep
    • Aug
    • Jul
    • Jun
    • May
    • Mar
    • Feb
    • Jan
  •     2013
    • Dec
    • Nov
    • Oct
    • Sep
    • Aug
    • Jul
    • Jun
    • May
    • Apr
    • Mar
    • Feb
    • Jan
  •     2012
    • Dec
    • Nov
    • Oct
    • Sep
    • Aug
    • Jul
    • Jun
    • May
    • Apr
    • Mar
    • Feb
    • Jan
  •     2011
    • Dec
    • Nov
    • Oct
    • Sep
    • Aug
    • Jul
    • Jun
    • May
    • Apr
    • Mar
    • Feb
    • Jan
  •     2010
    • Dec
    • Nov
    • Oct
    • Sep
    • Aug
    • Jul
    • Jun
    • May
    • Apr
    • Mar
    • Feb

Feed

Company-wide

  • Official Google Blog
  • Public Policy Blog
  • Student Blog

Products

  • Android Blog
  • Chrome Blog
  • Lat Long Blog

Developers

  • Developers Blog
  • Ads Developer Blog
  • Android Developers Blog
  • Google
  • Privacy
  • Terms