Location: PHPKode > projects > Monyet > plotter/backupline.php
<?php
/*
*/
include ("jpgraph/src/jpgraph.php");
include ("jpgraph/src/jpgraph_log.php");
include ("jpgraph/src/jpgraph_line.php");

//how i can pass the data array.. still try to figure it out
//finally i am using get method

$title = $_GET["title"];
$zoomin = $_GET['zoomin'];
$zoomout = $_GET['zoomout'];
$max = $_GET["max"];
//QUERY START and FINISH
if(isset($_GET['st'])){
	$q_start_time = " AND posttime >= \"".$_GET['st']."\"";
}
if(isset($_GET['ft'])){
	$q_finish_time = " AND posttime <= \"".$_GET['ft']."\"";
}
if(!isset($_GET['int'])){
	$interval = 0;
}
$agent_id = $_GET['agent_id'];

$db = new PDO('mysql:host=localhost;dbname=monyet', 'monyet', 'nyitnyit',array(
		     PDO::ATTR_PERSISTENT => true));
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

//get boundary
$sql = "SELECT green, red FROM pingmondef WHERE agent_id = ".$agent_id;
$stmt = $db->prepare($sql);
$stmt->execute();
$row_bound = $stmt->fetch(PDO::FETCH_OBJ);
$green = $row_bound->green;
$red = $row_bound->red;
$peak = $red;
$valley = $green;

$sql = "SELECT DATE_FORMAT(posttime, \"%k:%i\") as posttime, rtt FROM p_".$agent_id." WHERE rtt is not NULL ".$q_start_time." ".$q_finish_time."";
$stmt = $db->prepare($sql);
$stmt->execute();
$posttime = array();
$performance = array();
$greenline = array();
$redline = array();
while($row_host = $stmt->fetch(PDO::FETCH_OBJ)){
	$posttime[] = $row_host->posttime;
	$performance[] = $row_host->rtt; 
	if($peak < $row_host->rtt){
		$peak = $row_host->rtt;
	}
	if($valley > $row_host->rtt){
		$valley = $row_host->rtt;
	}
	$greenline[] = $green;
	$redline[] = $red;
}
$peak += ($peak-$valley)*0.15;
$valley -= ($peak-$valley)*0.05;
if($valley < 0){
	$valley = 0;
}
$interval = ceil(count($performance)/$max);
// Setup the graph
$graph = new Graph(500,300);
$graph->SetMarginColor('white');
$graph->SetScale("textlin",$valley,$peak);
$graph->SetFrame(false);
$graph->SetMargin(30,50,30,30);

$graph->title->Set($title);

$graph->yaxis->HideZeroLabel();
//$graph->ygrid->SetFill(true,'#hide@address.com','#hide@address.com');
$graph->xgrid->Show();

$graph->xaxis->SetTickLabels($posttime);
$graph->xaxis->SetTextTickInterval($interval);

$txt=new Text("[-]");
$txt->SetPos(482,25);
$txt->SetFont(FF_FONT1,FS_NORMAL);
if($zoomout){
	$txt->SetColor("black");
}
else{
	$txt->SetColor("gray");
}
$graph->AddText($txt);

$txt=new Text("[+]");
$txt->SetPos(482,45);
$txt->SetFont(FF_FONT1,FS_NORMAL);
if($zoomin){
	$txt->SetColor("black");
}
else{
	$txt->SetColor("gray");
}
$graph->AddText($txt);


// Create the first line
$p1 = new LinePlot($performance);
$p1->SetColor("navy");
$p1->SetLegend('performance');
$graph->Add($p1);

$p2 = new LinePlot($greenline);
$p2->SetColor("yellow");
//$p2->SetLegend('lower bound LAN');
$p2->SetStyle("dashed");
$graph->Add($p2);

// Create the third line
$p3 = new LinePlot($redline);
$p3->SetColor("red");
//$p3->SetLegend('upper bound LAN');
$p3->SetStyle("dashed");
$graph->Add($p3);

$graph->legend->SetShadow('hide@address.com',5);
$graph->legend->SetPos(0.1,0.1,'right','top');
// Output line
$graph->Stroke();
?>
Return current item: Monyet