title: Highcharts live data, json ajax
body: <p>My head is going to blow.</p>
  
  <p>livedata.php loads json when page open.
  live.php add point to graph.</p>
  
  <p>From livedata.php i got output like this:</p>
  
  <pre><code>[["Date.UTC(2016, 07-1, 28, 15, 08)",37],["Date.UTC(2016, 07-1, 28, 15, 08)",37],["Date.UTC(2016, 07-1, 28, 15, 08)",37],["Date.UTC(2016, 07-1, 28, 15, 08)",37],["Date.UTC(2016, 07-1, 28, 15, 08)",37],["Date.UTC(2016, 07-1, 28, 15, 08)",37]]
  </code></pre>
  
  <p>live.php output - only last row, looks like</p>
  
  <pre><code>["Date.UTC('.2016, 07-1, 29, 15, 40.')", 44]
  </code></pre>
  
  <p>I've got chart, live addPoint working, but no date on x-axis. What i do wrong?</p>
  
  <p>JS</p>
  
  <pre><code>var chart;
  
  function requestData() {
      $.ajax({
          url: 'live.php',
          success: function(point) {
              var series = chart.series[0],
                  shift = series.data.length &gt; 120; // shift if the series is 
  
                  chart.series[0].addPoint(eval(point));
  
                  setTimeout(requestData, 10000);    
          },
          cache: false
      });
  }
  $(function () {
          $.ajax({
          url: 'livedata.php',
          success: function(point) {
              chart = new Highcharts.Chart({
                  chart: {
                      renderTo: 'container',
                      type: 'areaspline',
  
                      events: {
                  load: requestData
              }
                  },
                  title: {
                      text: 'Revenue vs. Overhead',
  
                  },
                  subtitle: {
                      text: '',
  
                  },
                  xAxis: {
                      type: 'datetime'
  
  
                  },
                  yAxis: {
                      title: {
                          text: 'Amount'
                      },
                      plotLines: [{
                          value: 0,
                          width: 1,
                          color: '#808080'
                      }]
                  },
  
  
                  series: [{
  
              name: 'Random data',
              data:  eval(point )
          }]
              });
          },    
  
      });
  
  
  }); 
  </code></pre>
  
  <p>live.php</p>
  
  <pre><code>global $dbConnection;
      $stmt = $dbConnection-&gt;query('SELECT DATE_FORMAT(data,"%Y-%m-%d %H:%i") as dataa, humidity FROM sensorsdata order by id desc limit 1');    
      $row = $stmt-&gt;fetch(PDO::FETCH_ASSOC);
      $date_raw = strftime('%Y, %m-1, %d, %H, %M', strtotime($row[dataa]));
          $date_complete = "Date.UTC('.$date_raw.')";
      $ar = array($date_complete, $row[humidity]);
      echo json_encode($ar, JSON_NUMERIC_CHECK); 
  </code></pre>
  
  <p>livedata.php</p>
  
  <pre><code>global $dbConnection;
  $stmt = $dbConnection-&gt;query('SELECT DATE_FORMAT(data,"%Y-%m-%d %H:%i") as dataa, humidity FROM sensorsdata');    
  
  $result = $stmt-&gt;fetchAll();
  
  foreach ($result as $row) {
      $date_raw = strftime('%Y, %m-1, %d, %H, %M', strtotime($row[dataa]));
      $date_complete = 'Date.UTC('.$date_raw.')';
      $hum_for_chart[] = [$date_complete, $row[humidity]];
  
  }
  
  echo json_encode($hum_for_chart, JSON_NUMERIC_CHECK);
  </code></pre>
  
  <p>Chart:
  <a href="http://i.stack.imgur.com/vhicK.png" rel="nofollow">Chart</a></p>