1

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!

3
  • 2
    don't really know about charts but you can get the id by using charts.getId() Commented Sep 19, 2018 at 16:51
  • Ahh great. Not sure why I didn't think of that before. So I'm able to get the ID now, and have saved it to log. There has to be a way to copy/insert into the Doc with that specific id now too. Thanks! Commented Sep 20, 2018 at 17:57
  • your welcome. I really don't know how to insert it into the doc sorry Commented Sep 20, 2018 at 18:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.