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

111
Visualizações
How to update a Google Chart periodically?

Currently, I'm trying to update the value of my Google Line Chart. My aim is to update it periodically, so that I can obtain the result of a dynamic chart. Right now I need to refresh the whole page, but this is not a good solution.

I tried with setTimeout() function, but recalling the function drawChart() doesn't seem to be working. Here is my JavaScript code:

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
  google.charts.load('current', {'packages':['corechart']});
  google.charts.setOnLoadCallback(drawChart);

function drawChart()
  {
            // The intervals data as narrow lines (useful for showing raw source data)
    var options = {
        title: 'Valores de LDR1',
        vAxis: { ticks: [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]},
        curveType: 'function',
        lineWidth: 4,
        legend: 'none'
    }
    
    
    var ldr1 = new google.visualization.LineChart(document.getElementById('ldr1'));
    var ldr2 = new google.visualization.LineChart(document.getElementById('ldr2'));
    var ldr3 = new google.visualization.LineChart(document.getElementById('ldr3'));
    var ldr4 = new google.visualization.LineChart(document.getElementById('ldr4'));

    var data = google.visualization.arrayToDataTable(<?php prueba('ldr1') ?>);
    var data2 = google.visualization.arrayToDataTable(<?php prueba('ldr2') ?>);
    var data3 = google.visualization.arrayToDataTable(<?php prueba('ldr3') ?>);
    var data4 = google.visualization.arrayToDataTable(<?php prueba('ldr4') ?>);
        
    ldr1.draw(data, options);       
    options["title"] = "Valores de LDR2";               
    ldr2.draw(data2, options);
    options["title"] = "Valores de LDR3";               
    ldr3.draw(data3, options);
    options["title"] = "Valores de LDR4";               
    ldr4.draw(data4, options);
    updateChart();
    
    setTimeout(drawChart, 1000);
 }

The php code get values from the database, so as I see it, I only have to repeat the code of the function drawChart(), but this doesn't happen.

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