The following code can save an image to a sheet but I can't seem to figure out how to save it to Google Drive. Here is a Google sheet you can copy: https://docs.google.com/spreadsheets/d/1AkJqpwmq0-GTveneyuQugPL900LpTS2MDpQjHz_p5lk/edit?usp=sharing
function testchartbuild() {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName('Sheet1');
var chart = sheet.newChart()
.setChartType(Charts.ChartType.LINE)
.addRange(sheet.getRange('A1:A12'))
.setPosition(5, 5, 0, 0)
.build();
// create an image from that EmbeddedChart
sheet.insertImage(chart.getBlob(),6,1); // this works
// the file created is only 4 bytes long
var newFile = createGoogleDriveFile(chart.getBlob());
}
function createGoogleDriveFile(image) {
var newFile;
newFile = DriveApp.createFile('test.png',image,'image/png');//Create a new file in the root folder
return newFile;
};