Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
Google Sheets "Success Handler" Output to Variable

I'm pretty new to writing code and have been playing around with Google Sheets to try to get some basic interaction between some data I have in my sheet and a user interface using HTML. The idea is that I have data in my google sheet that I want to turn into a bar chart in HTML.

In my Sheets I have a column of data that has some values for each month in the format:
July 0
August 32
September 1261
October 0
etc...

In my Code.gs file I have a function that returns this as a list:

//Returns the corresponding yearly waste value for input month. Used for chart.
  function getYearlyWaste() {
    var yearlyWaste = spreadsheet.getRange(2, 28, 12).getValues();
    return yearlyWaste;
  }

When I run this in the Index.html:

google.script.run.withSuccessHandler(wasteVals).getYearlyWaste();

I want to be able to output the getYearlyWaste() function to a variable to use to draw a chart:

function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Month', 'Waste', 'Recycling'],
          ['Jan', yearlyWaste[0], yearlyRecycling[0]],
          ['Feb', yearlyWaste[1], yearlyRecycling[1]],
          ['Mar', yearlyWaste[2], yearlyRecycling[2]],
          ['Apr', yearlyWaste[3], yearlyRecycling[3]],
          ['May', yearlyWaste[4], yearlyRecycling[4]],
          ['Jun', yearlyWaste[5], yearlyRecycling[5]],
          ['Jul', yearlyWaste[6], yearlyRecycling[6]],
          ['Aug', yearlyWaste[7], yearlyRecycling[7]],
          ['Sep', yearlyWaste[8], yearlyRecycling[8]],
          ['Oct', yearlyWaste[9], yearlyRecycling[9]],
          ['Nov', yearlyWaste[10], yearlyRecycling[10]],
          ['Dec', yearlyWaste[11], yearlyRecycling[11]]
        ]);

However no matter what I do, I just get undefined. I feel like I'm missing something small, so any help would be appreciated.

As a note, I have tried pulling back individual values from the sheet and assigning them to an element ID value to be sure that the function is working right and I get the expected result.

Thanks in advance :)

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!