问题
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!
回答1:
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 ofchart.getBlob().setContentType('image/png')
.
Reference:
- setDimensions(width, height)
If this was not what you want, please tell me. I would like to modify it.
来源:https://stackoverflow.com/questions/52919710/google-script-how-to-send-tablechart-in-e-mail