Forum Moderators: coopster
require_once ('jpgraph-3.5.0b1/src/jpgraph.php');
require_once ('jpgraph-3.5.0b1/src/jpgraph_line.php');
//db connect
$mysqli = new mysqli("localhost","root","aaa","aaa");
if (mysqli_connect_errno()) {
printf("Connection failed: %s\n", mysqli_connect_error());
exit();
}
//variables
$ratio = array();
$mean = array();
$meanupper = array();
$meanlower = array();
$muTwoSD = array();
$mlTwoSD = array();
$datay1 = array();
$datay2 = array();
$datay3 = array();
$datay4 = array();
$datay5 = array();
$datay6 = array();
$arr_cmp1 = array();
$arr_cmp2= array();
//processing code below
//$ins = $mysqli->query("INSERT INTO sproc_run_history (stamptime,calledFrom) VALUES (NOW(),'mkimages.php')") or die($mysqli->error);
//while($mysqli->next_result()) $mysqli->store_result();
//mysqli_free_result($ins);
$rs = $mysqli->query("SELECT Company1, Company2 FROM results ORDER BY Company1") or die($mysqli->error);
//store the $rs into an array here?
while ($row = $rs->fetch_object()) {
$arr_cmp1[]= $row->Company1;
$arr_cmp2[] = $row->Company2;
}
while($mysqli->next_result()) $mysqli->store_result();
mysqli_free_result($rs);
$ct = count($arr_cmp1);
for ($cti=1; $cti<$ct; $cti++) {
$cmp1 = $arr_cmp1[$cti];
$cmp2 = $arr_cmp2[$cti];
unset($ratio,$mean,$meanupper,$meanlower,$muTwoSD,$mlTwoSD,$arr_);
echo $cti."<br />";
$result = $mysqli->query("CALL GetGraph('".$cmp1."','".$cmp2."')") or die($mysqli->error);
while ($row_sp = $result->fetch_object()) {
$ratio[] = array($row_sp->Ratio);
$mean[] = array($row_sp->Mean);
$meanupper[] = array($row_sp->MeanUpper);
$meanlower[] = array($row_sp->MeanLower);
$muTwoSD[] = array($row_sp->MUTwoSD);
$mlTwoSD[] = array($row_sp->MLTwoSD);
}
while($mysqli->next_result()) $mysqli->store_result();
mysqli_free_result($result);
/////////////////
//LOAD DATA FOR GRAPHS
/////////////////
unset($datay1,$datay2,$datay3,$datay4,$datay5,$datay6);
for($i = 0; $i < count($mean); $i++) {
$datay1[$i] = $ratio[$i][0];
$datay2[$i] = $meanlower[$i][0];
$datay3[$i] = $mean[$i][0];
$datay4[$i] = $meanupper[$i][0];
$datay5[$i] = $muTwoSD[$i][0];
$datay6[$i] = $mlTwoSD[$i][0];
}
// Setup the graph
$graph = new Graph(600,300);
$graph->SetScale("textlin");
$theme_class=new UniversalTheme;
$graph->SetTheme($theme_class);
$graph->img->SetAntiAliasing(false);
$graph->title->Set($cmp1.' / '.$cmp2);
$graph->SetBox(false);
$graph->img->SetAntiAliasing();
$graph->yaxis->HideZeroLabel();
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);
$graph->xgrid->Show();
$graph->xgrid->SetLineStyle("solid");
$graph->xaxis->SetTickLabels(array('1','2','3','4'));
$graph->xgrid->SetColor('#E3E3E3');
// Create the first line
$p1 = new LinePlot($datay1);
$graph->Add($p1);
$p1->SetColor("#6495ED");
//$p1->SetLegend('Line 1');
// Create the second line
$p2 = new LinePlot($datay2);
$graph->Add($p2);
$p2->SetColor("#FFAA00");
// Create the third line
$p3 = new LinePlot($datay3);
$graph->Add($p3);
$p3->SetColor("#000000");
// Create the 4thline
$p4 = new LinePlot($datay4);
$graph->Add($p4);
$p4->SetColor("#FFAA00");
// Create the 5thline
$p5 = new LinePlot($datay5);
$graph->Add($p5);
$p5->SetColor("#CC0000");
// Create the 6thline
$p6 = new LinePlot($datay6);
$graph->Add($p6);
$p6->SetColor("#CC0000");
$graph->legend->SetFrameWeight(1);
// Output line
$cmp1 = str_replace(".L", "", $cmp1);
$cmp2 = str_replace(".L", "", $cmp2);
$name = $cmp1."-".$cmp2;
$graph->Stroke('images/'.$name.'.jpg');
//$graph->Stroke();
}//end 1st while
$mysqli->close();