2

I'm creating a tablechart in Google Script and I want to send this through e-mail.

This is my code

var data = Charts.newDataTable()
      .addColumn(Charts.ColumnType.STRING, 'Month')
      .addColumn(Charts.ColumnType.NUMBER, 'In Store')
      .addColumn(Charts.ColumnType.NUMBER, 'Online')
      .addRow(['January', 10, 1])
      .addRow(['February', 12, 1])
      .addRow(['March', 20, 2])
      .addRow(['April', 25, 3])
      .addRow(['May', 30, 4])
      .build();

  var chart = Charts.newTableChart()
      .setDataTable(data)
      .enableSorting(true)
      .build();

  MailApp.sendEmail({
    to: "me@gmail.com",
    subject: "Test",
    htmlBody: "inline Google Logo<img src='cid:inImage'> images! <br>",
    inlineImages:
      {
        inImage: chart.getBlob().setContentType('image/png'),
      }
  });

The code gives the following error message on chart.getBlob().setContentType('image/png'):

"We're sorry, a server error occurred. Please wait a bit and try again".

Anyone any idea what's wrong?

Thanks!

TheMaster
  • 45,448
  • 6
  • 62
  • 85

1 Answers1

0

How about this modification?

From:

var chart = Charts.newTableChart()
    .setDataTable(data)
    .enableSorting(true)
    .build();

To:

var chart = Charts.newTableChart()
    .setDataTable(data)
    .enableSorting(true)
    .setDimensions(640, 480) // Added
    .build();

It sets the size of chart using setDimensions().

Note:

  • Also you can use chart.getAs('image/png') instead of chart.getBlob().setContentType('image/png').

Reference:

If this was not what you want, please tell me. I would like to modify it.

Tanaike
  • 181,128
  • 11
  • 97
  • 165