Created
April 18, 2015 22:25
-
-
Save pranavk/de5013d779431dbc0058 to your computer and use it in GitHub Desktop.
This analyses the data stored in mysql tables and show them in form of graph using HighCharts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$connect = mysql_connect("localhost", "username", "password"); | |
if($connect) { | |
mysql_select_db("sshaccount"); | |
$inputquery = "select UNIX_TIMESTAMP(time) as `time`, `out` from minute where user='username' order by time;"; | |
$arr = mysql_query ($inputquery); | |
while ($row = mysql_fetch_array($arr)) { | |
$datetime = $row['time']*1000; | |
$out = $row['out']; | |
$data[] = "[$datetime, $out]"; | |
} | |
} | |
?> | |
<html> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> | |
<script src="http://code.highcharts.com/stock/highstock.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7/prototype.js"></script> | |
<script src="http://code.highcharts.com/adapters/prototype-adapter.js"></script> | |
<script> | |
Highcharts.setOptions({ | |
global: { | |
useUTC: false | |
} | |
}); | |
function humanFileSize(bytesStr) { | |
var bytes = parseInt(bytesStr); | |
var thresh = 1000; | |
if(bytes < thresh) return bytes + ' B'; | |
var units = ['kB','MB','GB','TB','PB','EB','ZB','YB']; | |
var u = -1; | |
do { | |
bytes /= thresh; | |
++u; | |
} while(bytes >= thresh); | |
var res = bytes.toFixed(1)+' '+units[u]; | |
return res; | |
} | |
</script> | |
<script> | |
document.observe("dom:loaded", function() { | |
var chart = new Highcharts.StockChart({ | |
chart: { | |
renderTo: 'container' | |
}, | |
tooltip: { | |
formatter: function () { | |
var s = '<b>' + Highcharts.dateFormat('%A, %b %e, %Y', this.x) + '</b>'; | |
s += '<br/>' + humanFileSize(this.y); | |
return s; | |
} | |
}, | |
rangeSelector: { | |
selected: 1 | |
}, | |
title: { | |
text: 'Internet Usage by username' | |
}, | |
series: [{ | |
name: 'username', | |
data: [<?php echo join($data, ',') ?>], | |
}] | |
}); | |
}); | |
</script> | |
<body> | |
<div id="container" style="height: 400px; min-width: 310px"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment