Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

146
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda