Skip to content

Instantly share code, notes, and snippets.

@TheSkorm
Created January 6, 2013 10:51
Show Gist options
  • Select an option

  • Save TheSkorm/4466534 to your computer and use it in GitHub Desktop.

Select an option

Save TheSkorm/4466534 to your computer and use it in GitHub Desktop.
Graph for volts logging
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["annotatedtimeline"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('date', 'Time');
data.addColumn('number', 'Volts');
<?php
$row = 1;
if (($handle = fopen("/home/mwheeler/scripts/volts.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
$row++;
for ($c=0; $c < $num; $c++) {
if ($c==0){
$timestamp = $data[$c] * 1000;
} else if ($c==1) {
$a = str_replace(" V", "", $data[$c]);
if ($a>0) {
$volt = $a;
}
}
if ($volt & $timestamp){
$volts[$timestamp] = $volt ;
}
}
}
fclose($handle);
}
echo "data.addRows([";
$first = false;
foreach ($volts as $k => $v) {
if ($first == false){
echo "[new Date(".$k."),".$v."]\n";
$first = true;
}
else {
echo ",[new Date(".$k."),".$v."]\n";
}
}
echo "]);\n";
?>
var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div'));
chart.draw(data, {dateFormat: 'HH:mm MMMM dd, yyyy'});
}
</script>
</head>
<body>
<div id='chart_div' style='width: 1000px; height: 400px;'></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment