View Single Post
Old 01-08-2013, 04:42 PM   PM User | #1
rayTX
New to the CF scene

 
Join Date: Jan 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
rayTX is an unknown quantity at this point
Help generating multiple graphs

So I am looking for a little help to figure out what I am doing wrong here. I am trying to use data in a mysql database to create multiple graphs for each row returned. I'm not doing it correctly, and was hoping someone would help me out.
Here is the full code:

Code:
<?php

$conn = mysql_connect("localhost","user","passwrd")  or die(mysql_error());
mysql_select_db("db1", $conn) or die(mysql_error());

include("/usr/share/php/jpgraph-3.0.7/src/jpgraph.php");
include("/usr/share/php/jpgraph-3.0.7/src/jpgraph_line.php");
include('/usr/share/php/jpgraph-3.0.7/src/jpgraph_date.php');
include('/usr/share/php/jpgraph-3.0.7/src/jpgraph_utils.inc.php');


$servers = array('host1','host2','host3','host4');

foreach ($servers as $servername)
{

$sql = mysql_query("SELECT * FROM (SELECT * FROM db1.stattable1 WHERE host = '" . $servername . "' ORDER BY id DESC LIMIT 150) AS ttbl ORDER by id ASC");
while($row = mysql_fetch_array($sql))
{
        $time[] = $row['dt'];
        $load[] = $row['load'];
        $mem[] = $row['mem'];
        $cpu[] = $row['cpu'];

		
}


// Setup the graph

$graph = new Graph(1500,320,'auto');
$graph->SetScale("textlin");
$graph->yaxis->scale->SetGrace(25);
$graph->img->SetMargin(40,10,10,81);
$graph->SetShadow();
$graph->title->Set("$servername");


$graph->yaxis->HideZeroLabel();
$graph->yaxis->HideLine();
$graph->yaxis->HideTicks(false,false);
$graph->yaxis->title->Set("Title");
$graph->yaxis->SetTitleMargin(75);

$graph->xgrid->Show();
$graph->xaxis->HideLine();
$graph->xgrid->SetLineStyle("solid");
$graph->xaxis->SetTickLabels($time);
$graph->xaxis->SetLabelAngle(90);
$graph->xaxis->SetFont(FF_FONT0);
$graph->xgrid->SetColor('#E3E3E3');


$p1 = new LinePlot($load);
$graph->Add($p1);
$p1->mark->SetType(MARK_FILLEDCIRCLE);
$p1->mark->SetColor('#B22222');
$p1->mark->SetFillColor('#B22222');
$p1->mark->SetSize(2);
$p1->SetWeight(2);
$p1->SetColor("#B22222");
$p1->SetLegend("LoadAvg");

$p2 = new LinePlot($mem);
$graph->Add($p2);
$p2->mark->SetType(MARK_FILLEDCIRCLE);
$p2->mark->SetColor('#006600');
$p2->mark->SetFillColor('#006600');
$p2->mark->SetSize(2);
$p2->SetWeight(2);
$p2->SetColor("#006600");
$p2->SetLegend("Mem%");

$p3 = new LinePlot($cpu);
$graph->Add($p3);
$p3->mark->SetType(MARK_FILLEDCIRCLE);
$p3->mark->SetColor('#0000FF');
$p3->mark->SetFillColor('#0000FF');
$p3->mark->SetSize(2);
$p3->SetWeight(2);
$p3->SetColor("#0000FF");
$p3->SetLegend("CPU%");

$graph->legend->SetFrameWeight(1);
$graph->legend->SetPos(0,0,'right','top');

//Output line
$graph->Stroke();

}

?>
rayTX is offline   Reply With Quote