javascript - How to Plot data from Beginning -


i want develop dynamic page connected mysql database (from server) , display result in plot in real time. far managed data database , display graph. however, couldn't manage in real time.

i have database table named test , have 2 columns. 'id' , 'age'

id age  1 45  2 41  3 09  ......  60 11 

i want fetch data database 1 one , plot in chart, mean @ first fetch 45 , plot in chart , again fetch 41 , add in chart 45 , on... , when new data point come, old data shift.it continue until complete fetching.

<?php include("md.php"); $arr = array(0,0,0,0,0,0,0,0,0);  $con = mysqli_connect('127.0.0.1','user2','123','test'); $select="select age tab"; $res = mysqli_query($con, $select); $i=0;                       while ($row=$res->fetch_assoc()) { $arr=array_slice($arr,1,8); $arr[]=array($i++, (int)$row['age']); echo json_encode($arr)."<br>"; }   ?> 

i'm getting output follows=

[0,0,0,0,0,0,0,0,0,[0,45]]  [0,0,0,0,0,0,0,0,[0,45],[1,41]]  [0,0,0,0,0,0,0,[0,45],[1,41],[2,11]]  [0,0,0,0,0,0,[0,45],[1,41],[2,11],[3,21]]  [0,0,0,0,0,[0,45],[1,41],[2,11],[3,21],[4,44]]  ............................. [[1,41],[2,11],[3,21],[4,44],[5,13],[6,15],[7,12],[8,7],[9,14],[10,11]]  ........................ [[41,4],[42,11],[43,1],[44,54],[45,13],[46,15],[47,2],[48,7],[49,14],[50,61]] 

then when i'm plotting data, taking last 10 values. want data in chart beginning 1 one

<script type="text/javascript">  var data=[]; function f(){ data= <?php echo json_encode($arr) ?>; }  var options={                 series: {                         lines: {                                 show: true,                                 linewidth: 2,                                  },                         points:{                                 show: true                                 }                         },              }; $(document).ready(function () { f(); var dataset=[               {                  label: "data",                  data: data,                  points: {                              symbol: true                         }               }             ];       $.plot($("#flot-container"), dataset , options); function update() { f(); data.shift();   $.plot($("#flot-container"), dataset, options); settimeout(update, 5000);       }       update(); });  </script> 

i want output as

how can execute it?where doing wrong?please help.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -