My goal is to create google documents using information from a google sheet with google app script.
I can generate a radar chart from the data in the google sheets.
How about this answer?
I think that this might be a bug. In this case, as a workaround, I use a Google Slides which can directly put the chart created with Google Spreadsheet. When the blob is retrieved from the chart put to the Google Slides, the blob is the same with the chrat on Google Spreadsheet.
When your script is modified, please modify as follows.
From:var image = sheet.getCharts()[0].getBlob().getAs('image/png');
To:
const slides = SlidesApp.create("temp");
const imageBlob = slides.getSlides()[0].insertSheetsChartAsImage(chart).getAs("image/png");
DriveApp.getFileById(slides.getId()).setTrashed(true);
DriveApp.createFile(imageBlob);
imageBlob
is created with DriveApp.createFile(imageBlob)
as a file, the following result can be obtained.When image
and imageBlob
are created as a file, the left and right images are obtained, respectively.
If you want to put the correct chart image to Google Document using this workaround, please modify as follows.
const slides = SlidesApp.create("temp");
const imageBlob = slides.getSlides()[0].insertSheetsChartAsImage(chart).getAs("image/png");
DriveApp.getFileById(slides.getId()).setTrashed(true);
// This script puts the retrieved image blob to the Google Document.
DocumentApp.openById("### Document ID ###").getBody().insertImage(0, imageBlob);