2

I would like to add a "Gauge chart" in Google sheets programmatically. This is an example that I found on the internet but it is coded to display the chart on a webpage. I will, however, try to work off of that example code. But, any help is appreciated. Here's the example https://developers.google.com/chart/interactive/docs/gallery/gauge

TheMaster
  • 45,448
  • 6
  • 62
  • 85
Jrules80
  • 178
  • 12

1 Answers1

3
  • You want to create "Gauge chart" to the Spreadsheet.
  • You need a sample script for achieving this with Google Apps Script.

If my understanding is correct, how about this sample script?

Sample script:

Before you run the script, as a test case, please set sample and 50 to the cells of "A1" and "B1", respectively.

function myFunction() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var chart = sheet.newChart()
    .setChartType(Charts.ChartType.GAUGE)
    .addRange(sheet.getRange('A1:B1'))
    .setPosition(3, 1, 0, 0)
    .setOption('height', 300)
    .setOption('width', 300)
    .setOption('title', 'Sample chart')
    .build();
  sheet.insertChart(chart);
}

Result:

enter image description here

References:

If I misunderstood your question and this was not the direction you want, I apologize.

Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • Perfect! I am pretty sure that is what I want but is this manipulative? Can you add code where you are able to change the position of the dial according to a value, please? – Jrules80 Sep 10 '19 at 12:38
  • @Jrules80 Thank you for replying. Although I'm not sure whether I could correctly understand about your replying, when you want to change the dial of the gauge chart, how about modifying the value? In above case, when you modify `50` of the cell "B1", the dial is changed. But unfortunately, the dial is changed soon. It seems that this is the specification. If I misunderstood your new question, I apologize. – Tanaike Sep 10 '19 at 22:10
  • Hello, Tanaike - At this tiime, I do not have to pursue this approach. But, when the need comes, I will check back. I am accepting your solution. Thank you for your support. – Jrules80 Sep 13 '19 at 01:46