javascript - Highcharts live data not updating after changing PHP variable -


i've got live updating highchart on page, index.html, calls php script, datatest.php, parse csv file, outputs result json , adds new point on chart:

$.ajax({     url: 'datatest.php',     success: function(point) {         var series = chart.series[0],             shift = series.data.length > 20; // shift if series longer 20          // add point         chart.series[0].addpoint(eval(point), true, shift);          // call again after 1 second         settimeout(requestdata, 1000);       },     cache: false }); 

the basic php script stores "line" session variable, each time script called, parses next line of csv file. csv file has 2 columns, 1 "hi" , 1 "lo".

i'm trying add couple of buttons page can dynamically change column of csv file php script returning. code these buttons below:

<form method="post" action ="datatest.php">     <input type="submit" name="highwind" value="hi"/>     <input type="submit" name="lowwind" value="lo"/> </form> 

the chart runs , updates fine default (low) values, when press either of above buttons, chart stops. php code have:

<?php  $i = 0; session_start();  $_session['line'] = isset($_session['line']) ? ++$_session['line'] : 0; $_session['hiorlo'] = isset($_session['hiorlo']) ? $_session['hiorlo'] : "lo";  $handle = fopen('windspeed.csv', 'r');   while(($windvals = fgetcsv($handle, 1000, ',')) && $i <= $_session['line']) {     $i++; } if(!$windvals) {    $_session['line'] = 0; }  header("content-type: text/json"); $x = time() * 1000;  $_session['hiorlo'] = isset($_post["highwind"]) ? $_post["highwind"] : "low";   //$hiorlo post code if ($_session['hiorlo'] == "hi") {     $y =  (float)$windvals[0]; } else {     $y = (float)$windvals[1]; }  // create php array , echo json $ret = array($x, $y); echo json_encode($ret);  header("location: index.html"); // return frontend (index.html)  ?> 

the funny thing is, when comment out header("location: index.html"), i'm redirected json output of php script expected, , displaying correct values depending on button pressed. however, header code left in, chart stops after press.

any appreciated!

thanks, kevin

you going wrong approach.you seem try achieving dynamic chart refresh , need to:

  1. make ajax call on button click's
  2. pass parameter's function (line no in case. can stored in javascript state variable)
  3. write function remove previous data/point chart , add new point.

that should approach follow charts , dynamic data pushing.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -