javascript - Highcharts with ajax / json -
this isn't problem highcharts rather more javascript function passes data. first off , java skills pretty basic .. , pretty damn bad honest. laughing @ code equivalent of laughing @ handy capped people :)
anyway, idea pretty simple , i'm feeding highcharts graphs network traffic gathered php script via snnp call.
the data encoded json_encode , output looks this: [1464786728000,13850896] first value current time , second value traffic measured in octets. i've included php script below.
now of works pretty , data gets collected , graphs plots in real time no issues. problem comes in have pass current value javascript function can deduct previous value current value i'm left difference between intervals. need multiply value 8 ... since i'm converting octets bits , divide poll interval. should rather simple reason i'm unable read previous variable when pass it.
i hope i'm making sense here ;)
function requestdata(previous) { var poll = 1000; $.ajax({ url: 'grabethertraffic.php?canopyip=<? echo $canopyip; ?>', success: function(point) { var series = chart.series[0] ; shift = series.data.length > 20; // shift if series // little formula figure out current thoughput on interface is. // need deduct previous data current data when // timeout expires , function fires again. var bps = (series - previous) * 8 / poll; // plot bps.. bps.addpoint(point, true, shift); // here's attempt pass current data function when fires again. settimeout(function () { requestdata(series); }, poll); }, cache: false }); }
php script...
<?php // set json header include 'snmpiods.php'; $canopyip = $_request['canopyip']; $x = time() * 1000; $gatherrx = getsnmpdata("$canopyip","1.3.6.1.2.1.2.2.1.10"); list($null, $gatherrx) = split(" ", $gatherrx, 2); settype($gatherrx, "integer"); header("content-type: text/json"); $ret = array($x, $gatherrx); echo json_encode($ret); ?>