I want to establish a linked chart within a Google Doc. The chart is already built in a corresponding Google Sheet.
I've found where you extract hyperlinks (See here), but I can't figure out how to grab the corresponding link for the chart.
Most of what I've found searching wants to build the chart within sheets and paste it as an image one time. What I'm wanting to do is create the LINK between the existing chart in my sheet and the chart that the script will insert for me.
If I need to create the chart initially, grab the chart link, and then post that into the Doc, that's fine too.
Here's what I have so far:
function embedchart() {
var doc = DocumentApp.openById('file id')
var sheet = SpreadsheetApp.openById('sheet file id')
var sheetName = sheet.getSheetByName('SheetName')
var range = sheet.getRange("A2:B5");
var chart = sheet.getCharts()[0];
chart = chart.modify()
.addRange(range)
.setOption('title', 'Updated!')
.setOption('animation.duration', 500)
.setPosition(2,2,0,0)
doc.getBody().appendImage(image)
}
This does a fine job of appending the chart into my Doc initially, but it doesn't create the link effect that would be found by going to Insert > Chart > From Sheets OR Chart.
Thank you for your help!