chart.php 2.24 KB
<!DOCTYPE html>
<html>
<?php
	$filename = "/home/pi/Desktop/vAlert/rec/20180118130646_1001[0001]_541.csv";
	$row = 0;
	$i = 0;
	if (($handle = fopen($filename, "r")) !== FALSE) {
        while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {
			if($row == "2") $time = explode("e:",$data['0']); 
			//find RecordLength
			if($row == "3") $sec = explode(":",$data['0']); 	 
			if($row >= "28"){
				$array_z[] = $data['0'];
				$array_x[] = $data['1'];
				$array_y[] = $data['2'];
			}
			$row++;
        }
		
        
    }
	foreach($array_x as $key=>$value){
		$radial[]="{x:".$key.",y:".$value."}";
	}
	foreach($array_z as $key=>$value){
		$vertical[]="{x:".$key.",y:".$value."}";
	}
	foreach($array_y as $key=>$value){
		$transverse[]="{x:".$key.",y:".$value."}";
	}
?>
<head>
<script>
	window.onload = function () {
		var transverse = {
			animationEnabled: true,
			zoomEnabled: true,
			title:{
				text: "Transverse"
			},
			data: [{
				type: "line",
				dataPoints: [
					<?php echo implode(",",$transverse); ?>
				]
			}],
			axisY:{
				includeZero: false
			}
		};
		$("#chartContainer2").CanvasJSChart(transverse);
		
		var radial = {
			animationEnabled: true,
			zoomEnabled: true,
			title:{
				text: "Radial"
			},
			data: [{
				type: "line",
				color: "#FF0000",
				dataPoints: [
					<?php echo implode(",",$radial); ?>
				]
			}],
			axisY:{
				includeZero: false
			}
		};
		$("#chartContainer").CanvasJSChart(radial);
		
		var vertical = {
			animationEnabled: true,
			zoomEnabled: true,
			title:{
				text: "Vertical"
			},
			data: [{
				type: "line",
				color: "#33FF33",
				dataPoints: [
					<?php echo implode(",",$vertical); ?>
				]
			}],
			axisY:{
				includeZero: false
			}
		};
		$("#chartContainer1").CanvasJSChart(vertical);
		
		
	}
</script>
	<h1>StartTime : <?php echo $time['1'];?> &nbsp;&nbsp;&nbsp;Record Length(sec) : <?php echo $sec['1'];?></h1>
<div id="chartContainer2" style="height: 300px; width: 100%;"></div>
<div id="chartContainer" style="height: 300px; width: 100%;"></div>
<div id="chartContainer1" style="height: 300px; width: 100%;"></div>
<script src="https://canvasjs.com/assets/script/jquery-1.11.1.min.js"></script>
<script src="https://canvasjs.com/assets/script/jquery.canvasjs.min.js"></script>
</body>
</html>