How to plot a jpgraph from dropdown list?
I want to use a drop-down to choose the variables. After choosing,it will
go to MYSQL to look for the data and information. After which use i want
to data and plot a graph using jpgraph. However, it didn't work... below
is my codes. Can any of the pros here help me?
try.php
<?php
if ($_GET){
$cw = $_GET['cw'];
$cw2 = $_GET['cw2'];
$connect = mysql_connect("localhost","root","");
if ($connect){
mysql_select_db ("test" , $connect);
$query= "SELECT * FROM testing WHERE CW='". $cw."' OR CW='".
$cw2."' " ;
$results = mysql_query($query);
}}
require_once('trying.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>search</title>
</head>
<body>
<form action="" method="GET">
<select name="cw" id="cw">
<option value="13W07">13W07</option>
<option value="13W13">13W13</option>
<option value="13W6">13W6</option>
</select>
<select name="cw2" id="cw2">
<option value="13W07">13W07</option>
<option value="13W13">13W13</option>
<option value="13W6">13W6</option>
</select>
<input name="submit" type="submit" value="Submit" />
</form>
</body>
</html>
trying.php
<?php
require_once ('jpgraph/src/jpgraph.php');
require_once ('jpgraph/src/jpgraph_line.php');
$dataUptime = array();
$dataCW = array();
while($rows = mysql_fetch_array($results)){
$dataUptime[] = $rows['Uptime'];
$dataCW[] = $rows['CW'];
}
$datay1 = $dataUptime;
// Setup the graph
$graph = new Graph(500,250);
$graph->SetScale("textlin");
$theme_class=new UniversalTheme;
$graph->SetTheme($theme_class);
$graph->img->SetAntiAliasing(false);
$graph->title->Set('Tool Type');//tooltype is the title of graph
$graph->SetBox(false);
$graph->img->SetAntiAliasing();
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);
$graph->xgrid->Show();
$graph->xgrid->SetLineStyle("solid");
$graph->xaxis->SetTickLabels($dataCW);
$graph->xgrid->SetColor('#E3E3E3');
// Create the first line
$p1 = new LinePlot($datay1);
$graph->Add($p1);
$p1->SetColor("#000");
$p1->mark->SetType(MARK_FILLEDCIRCLE,'',1.0);
$p1->value->Show();
$p1->SetLegend('Line 1');
/*Create the second line
$p2 = new LinePlot($datay2);
$graph->Add($p2);
$p2->SetColor("#B22222");
$p2->SetLegend('Line 2');
*/
$graph->legend->SetFrameWeight(1);
// Output line
$graph->Stroke();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Jpgraph</title>
</head>
<body>
</body>
</html>
No comments:
Post a Comment