How to include quickchart-js using google app script

I’m developing something through google apps script and want to create charts by quickchart, how can I include quickchart library ? Thanks

Hi Peter,

I believe we spoke on github but I’m reproducing the answer here:

In Google Apps Script, it’s probably easiest to construct the QuickChart URL manually.

For example:

function GetChartUrl(values) {
  var width = 500;
  var height = 300;
  var backgroundColor = 'white';
  var config = `{
  type: 'bar',
  data: {
    labels: ['Q1', 'Q2', 'Q3', 'Q4'],
    datasets: [{
      label: 'Data',
      data: [${values.join(',')}]
    }]
  }
}
`;
  return `https://quickchart.io/chart?c=${encodeURIComponent(config)}&w=${width}&h=${height}&bkg=${backgroundColor}&devicePixelRatio=1`
}

And the formula in Google Sheets:

=GetChartUrl(A2:A6)

or, to display an image:

=IMAGE(GetChartUrl(A2:A5))

Here’s an example sheet that generates a chart URL: QuickChart - Google Apps Script example - Google Sheets

1 Like

how to add title in that chart?

i try your code but no title in chart

can you help me? TIA

Hello, please refer to the documentation on Chart Titles. If you’re still having issues, create a new post and include your chart config.