Hi all,
I was wondering if any of you code gurus could help me with something I’d like to do with this temp graph.
I’d like to make it fill the below zero temperatures with blue, and the above zero temperatures with red.
Also, change the plot line from a fixed color to the same, ie. red if above zero and blue if below zero.
Here’s the graph:
And here’s my current code (don’t pay so much attention to the colors I’ve chosen etc it’s just for testing):
<?php
// Graphs Package V2.1 16th March 2008
if (!file_exists("graphsconf.php")) include("error_msg.php");
include ("graphsconf.php");
if (!file_exists($jploc."jpgraph.php")) {
$string = "Unable to find JPGraph files";
create_image1($string,$jploc);
exit;
}
include ($jploc."jpgraph.php");
include ($jploc."jpgraph_line.php");
$clientrawextra = get_raw("${hostloc}clientrawextra.txt");
//temp=========================================================================
$y=array($clientrawextra['21'],$clientrawextra['22'],$clientrawextra['23'],$clientrawextra['24'],
$clientrawextra['25'],$clientrawextra['26'],$clientrawextra['27'],$clientrawextra['28'],$clientrawextra['29'],
$clientrawextra['30'],$clientrawextra['31'],$clientrawextra['32'],$clientrawextra['33'],$clientrawextra['34'],
$clientrawextra['35'],$clientrawextra['36'],$clientrawextra['37'],$clientrawextra['38'],$clientrawextra['39'],
$clientrawextra['40'],$clientrawextra['566'],$clientrawextra['567'],$clientrawextra['568'],$clientrawextra['569']);
$datay = $y;
if ($temp_conv == 1.8) {
array_walk($datay, "CtoF");
}
//Check for negative values in array and do a SetAuotMin(0) if none
array_walk($datay, "NegVal");
$negvalue1 = $negvalue;
// Check for positive values in array
array_walk($datay, "PosVal");
$posvalue1 = $posvalue;
$negvalue = 0;
$posvalue = 0;
if (($negvalue1 == 1) or ($negvalue3 == 1)) $negvalue = 1;
if (($posvalue1 == 1) or ($posvalue3 == 1)) $posvalue = 1;
if (($negvalue1 == 0) and ($negvalue3 == 0)) $negvalue = 0;
if (($posvalue1 == 0) and ($posvalue3 == 0)) $posvalue = 0;
if ($negvalue == 0) {
if ($temp_conv == 1) $automin = '$graph->yaxis->scale->SetAutoMin(0);';
if ($temp_conv == 1.8) $automin = '$graph->yaxis->scale->SetAutoMin(32);';
$grace = '$graph->yaxis->scale->SetGrace(5);';
}
if (($negvalue == 1) and ($posvalue == 0)) {
if ($temp_conv == 1) $automin = '$graph->yaxis->scale->SetAutoMax(0);';
if ($temp_conv == 1.8) $automin = '$graph->yaxis->scale->SetAutoMax(32);';
$grace = '$graph->yaxis->scale->SetGrace(0,5);';
}
if (($negvalue == 1) and ($posvalue == 1)) {
$automin = '';
$grace = '$graph->yaxis->scale->SetGrace(5,5);';
}
//create timearray for the x-axis
$x=array($clientrawextra['459'],$clientrawextra['460'],$clientrawextra['461'],$clientrawextra['462'],
$clientrawextra['463'],$clientrawextra['464'],$clientrawextra['465'],$clientrawextra['466'],$clientrawextra['467'],
$clientrawextra['468'],$clientrawextra['469'],$clientrawextra['470'],$clientrawextra['471'],$clientrawextra['472'],
$clientrawextra['473'],$clientrawextra['474'],$clientrawextra['475'],$clientrawextra['476'],$clientrawextra['477'],
$clientrawextra['478'],$clientrawextra['578'],$clientrawextra['579'],$clientrawextra['580'],$clientrawextra['581']);
$datax = $x;
// Create the graph and specify the scale for both Y-axis
$graph = new Graph($xsize,$ysize,"auto",30);
$graph->SetScale("textlin");
$graph->SetShadow();
$graph->SetMarginColor("$margincolour");
// Adjust the margin
$graph->SetMargin($lm,$rm,$tm,$bm);
// Create the two linear plot
$lplot1=new LinePlot($datay); // Temp
// Add the plot to the graph
$graph->Add($lplot1);
//titles
//$graph->title->Set("$txt_temp - Last 24 hrs ($temp_unit)");
//$graph->title->Align("center","top");
//$graph->title->SetFont(FF_ARIAL,FS_BOLD,10);
//$graph->title->SetColor("$textcolour");
//x-axis
//$graph->xaxis->title->SetColor("$xtextcolour");
//$graph->xaxis->title->Set("$txt_24h");
//$graph->xaxis->title->SetFont(FF_ARIAL,FS_BOLD,8);
$graph->xaxis->SetFont(FF_ARIAL,FS_BOLD,8);
$graph->xaxis->SetTitlemargin(25);
$graph->xaxis->SetLabelMargin(10);
$graph->xaxis->SetTickLabels($datax);
$graph->xaxis->SetLabelAngle($label_angle);
$graph->xaxis->SetTextLabelInterval($label_interval);
$graph->xaxis->SetPos("min");
$graph->xaxis->HideTicks(true,true);
$graph->xaxis->SetColor("$xtextcolour");
$graph->xgrid->Show(true);
//y-axis
$graph->yaxis->SetFont(FF_ARIAL,FS_BOLD,8);
$graph->yaxis->SetColor("$ytextcolour");
$graph->yaxis->SetLabelFormat("%0.0f");
$graph->yaxis->HideTicks(false,false);
eval($automin);
eval($grace);
//y2-axis
//$graph->y2axis->SetFont(FF_ARIAL,FS_BOLD,8);
//$graph->y2axis->SetColor("$y2textcolour");
//$graph->yaxis->SetLabelFormat("$temp_format");
//$graph->y2axis->HideTicks(true,true);
//$graph->y2axis->scale->SetAutoMin(0);
// Set the colors for the plots
if (($negvalue1 == 0) and ($posvalue1 == 1)) $lplot1->SetColor("$temp_col1");
if (($negvalue1 == 1) and ($posvalue1 == 0)) $lplot1->SetColor("$temp_col2");
if (($negvalue1 == 1) and ($posvalue1 == 1)) $lplot1->SetColor("$temp_col3");
if (($negvalue1 == 1) and ($posvalue1 == 0)) $lplot1->SetFillColor("#[email protected]");
if (($negvalue1 == 1) and ($posvalue1 == 1)) $lplot1->SetFillColor("#[email protected]");
$lplot1->SetWeight(1);
// Setup a background gradient image
$graph->SetBackgroundGradient('white','navy:0.5',GRAD_HOR,BGRAD_PLOT);
// Set the legends for the plots
//$graph->legend->SetFont(FF_ARIAL,FS_NORMAL,7);
//$lplot1->SetLegend("$txt_temp1");
// Adjust the legend position
//$graph->legend->SetLayout(LEGEND_HOR);
//$graph->legend->Pos(0.02,0.01,'right','top');
// Display the graph
$graph->Stroke();
?>
Best Regards,
Martin