Location: PHPKode > projects > Monyet > plotter/linewindow.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"];
//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'];

$hostname = "localhost";
$database = "monyet";
$username = "monyet";
$password = "nyitnyit";
$connection = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR); 

mysql_select_db($database,$connection);

//get boundary
$query_bound = "SELECT green, red FROM pingmondef WHERE agent_id = ".$agent_id;
$bound = mysql_query($query_bound, $connection) or die(mysql_error());
$row_bound = mysql_fetch_assoc($bound);
$green = $row_bound['green'];
$red = $row_bound['red'];
$peak = $red;
$valley = $green;

$query_hosts = "SELECT DATE_FORMAT(posttime, \"%k\") as hour, DATE_FORMAT(posttime, \"%k:%i\") as posttime, rtt FROM p_".$agent_id." WHERE rtt is not NULL ".$q_start_time." ".$q_finish_time."";
$list_hosts = mysql_query($query_hosts, $connection) or die(mysql_error());
	
$posttime = array();
$performance = array();
$greenline = array();
$redline = array();
for($i=0;$i<23;$i++){
	$row_hosts = mysql_fetch_assoc($list_hosts);
	if($i == $row_hosts['hour']){
		for($j=0;$j<4;$j++){
			$row_hosts = mysql_fetch_assoc($list_hosts);
			$performance[] = $row_hosts['rtt']; 
			if($peak < $row_hosts['rtt']){
				$peak = $row_hosts['rtt'];
			}
			if($valley > $row_hosts['rtt']){
				$valley = $row_hosts['rtt'];
			}
		}
	}
	else{
		$performance[] = 0; 
	}
	$posttime[] = $i;
	$greenline[] = $green;
	$redline[] = $red;
}
$peak += ($peak-$valley)*0.05;
$valley -= ($peak-$valley)*0.05;
if($valley < 0){
	$valley = 0;
}
// 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(false,'#hide@address.com','#hide@address.com');
$graph->xgrid->Show();

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

// 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