Advertisement
edsheut

Highchart function

May 19th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //GLOBAL VARS TO MANAGE DATA
  2. var TempTxR = [0,0]; //old_tx,new_tx
  3. var TempRxR = [0,0]; //old_rx,new_rx
  4. var FlagFirstTimeR = 0;
  5. var interval = 5;
  6. var window = 20;
  7. ///FUNCTION FOR RIGHT CHART
  8. function requestDataRight() {
  9.     $.ajax({
  10.         url: 'cgi-bin/JSON_A.pl', //FUNCTION TO POPULATE RIGHT CHART
  11.         success: function(point) {
  12.             var series = charRight.series[0],
  13.                 shift = series.data.length > window; // shift if the series is longer than 20
  14.             // dissect point
  15.             var punto = eval(point);
  16.             // Calculate difference between new and old points
  17.             TempTxR[0] = TempTxR[1];
  18.             TempTxR[1] = punto[1];
  19.             TempRxR[0] = TempRxR[1];
  20.             TempRxR[1] = punto[2];
  21.             // Calculate delta
  22.             var diff = (TempTxR[1] - TempTxR[0])/interval;
  23.             var puntoSerieTx = [punto[0],diff];
  24.             diff = (TempRxR[1] - TempRxR[0])/interval;
  25.             var puntoSerieRx = [punto[0],diff];                
  26.             // Add the point
  27.             if (FlagFirstTimeR == 0){                  
  28.                 FlagFirstTimeR = 1; //First point is off the scale =(
  29.             }else{                 
  30.                 // add the point
  31.                 charRight.series[0].addPoint(puntoSerieTx, true, shift);
  32.                 charRight.series[1].addPoint(puntoSerieRx, true, shift);
  33.             }  
  34.         },
  35.         cache: false
  36.     });
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement