SQL select query from database in the Line chart is not updating values (PHP)

« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by Aline on 19th August 2016
I have a problem using mysql database and php when creating a chart.

Here is my code:
<?php session_start(); ?>
<!DOCTYPE html >
     <link rel="stylesheet" href="demos.css" type="text/css" media="screen" />
     <script src="RGraph/libraries/RGraph.common.core.js" ></script>
     <script src="RGraph/libraries/RGraph.line.js" ></script>

     <title>Line chart with scrolling effect</title>

     <meta name="robots" content="noindex,nofollow" />
     <meta name="description" content="A chart which updates itself every 250ms producing a scrolling effect" />


     <h1>Line chart with scrolling effect</h1>

     <canvas id="cvs" width="600" height="250">[No canvas support]</canvas>

         data = RGraph.arrayPad([], 500);
         function DrawGraph ()


             var line = new RGraph.Line({
                 id: 'cvs',
                 data: data,
                 options: {
                     colors: ['green'],
                     linewidth: 1,
                     filled: true,
                     fillstyle: 'rgba(128,255,128,0.5)',
                     ymax: 60,
                     tickmarks: null,
                     shadow: false,
                     numxticks: 5,
              labels: ['0s','5s','10s','15s','20s','25s'],

                  // labels: ['Now','25s','50s','75s','100s','125s'],
                     backgroundGridAutofitNumvlines: 5,
                     textAccessible: true


         $dbh = new PDO("mysql:host=$host;dbname=VGW", $user , $pass );

$req="SELECT CPUUtilization from G_info where login_id='".$_SESSION['login_device_id']."' limit 30;";
   echo "Lecture impossible";
  if ($ligne != null) {
  r = <?php echo $f; ?>; data = [r].concat(data);data.pop();
   while ($ligne = $stmt->fetchObject()) ;
{echo "<br> \n No such result";}

             setTimeout(DrawGraph, 2500);

         window.onload = function ()

The problem is that in the output of the chart:

If the 30 values in the database (table g_info) are modified, the query returns the same result of the first entry in the function. It seems like the $req is not updating the values.

Any idea?

Thanks in advance.
Posted by Richard on 19th August 2016
Hi there,

Sorry my PHP is very rusty these days and I've not used PDO before. I'd suggest though that before you worry about RGraph you get your PDO stuff working as you want it to. For a Line chart you would want it (your data variable by the looks of it) to be an array of values that looks something like this:


If you need it you can use print_r() to print the contents of PHP variables so that you can see what they old:



Add a reply

« Back to message list