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

110
Views
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
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!