<?php /******************************************* /* Programm count.php4 /* displays data selected in menugraph.php4 /* (c) Copyright 2002, Jens Bierkandt /* e-mail: jens@bierkandt.org /* Entstanden im Rahmen meiner Diplomarbeit /******************************************* */ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: public"); set_time_limit(60); include ("jpgraph-1.6.1/src/jpgraph.php"); include ("jpgraph-1.6.1/src/jpgraph_line.php"); include ("/home/schtorch/public_html/diplom/config.php4"); // Check variables and initialize if (!isset($table)) Header("Location: index.php4"); // Forward user to main page to reselect table //if (!isset($sensor[0])) $sensor[0]="1"; if (!(isset($width_graph) || isset($height_graph))) { $width_graph = 600; $height_graph = 400; }; if ($width_graph < 600 || $height_graph < 400) { $width_graph = 600; $height_graph = 400; }; // Initialize connection to DB $db = mysql_connect($hostname, $username, $password); mysql_select_db($database, $db); echo mysql_error(); // Prefill array to have continuous data $count_min = 127; $count_max = 0; for ($b = 0; $b < sizeof($sensor); $b++) { $result = mysql_query("SELECT MIN(sensor".$sensor[$b]."), MAX(sensor".$sensor[$b].") FROM `tmp`", $db); echo mysql_error($db); $row = mysql_fetch_row($result); if (round($row[0]) < $count_min) $count_min = round($row[0]); if (round($row[1]) > $count_max) $count_max = round($row[1]); } //echo $count_max."\n"; for ($i = 0; $i <= ($count_max-$count_min); $i++) { $datax[$i] = $i+$count_min; //echo $datax[$i]." "; for ($b = 0; $b < sizeof($sensor); $b++) { $ydata[$b][$i] = ""; } } // Select data for ($b = 0; $b < sizeof($sensor); $b++) { $query = "SELECT count(*), round(sensor".$sensor[$b].") FROM `tmp` WHERE sensor".$sensor[$b]."!='' GROUP BY ROUND(sensor".$sensor[$b].") ASC"; $result = mysql_query($query, $db); echo mysql_error($db); $i = 0; while($row = mysql_fetch_row($result)) { while ($i+$count_min < $row[1]) $i++; $ydata[$b][$i] = $row[0]; //echo "Sensor".$b.":".$datax[$i].":".$ydata[$b][$i]." "; $i++; } } $x_tick_diff = 1; if (isset($datax[0])) { $x_temp = round(($width_graph-120-50)/50); $x_tick_diff = (sizeof($datax)-1)/$x_temp; //echo $x_tick_diff; } if ($x_tick_diff < 10) $x_tick_diff = round($x_tick_diff); // Create the graph. These two calls are always required $graph = new Graph($width_graph, $height_graph, "auto"); $graph->SetScale("textlin"); // Create the linear plots $color = array("blue", "green", "orange", "magenta", "black", "red"); for ($a = 0; $a < 6; $a++) { if (isset($sensor[$a])) { $lineplot[$a] = new LinePlot($ydata[$a]); $lineplot[$a]->SetFillColor($color[$a]); $lineplot[$a]->SetWeight(1); $lineplot[$a]->SetLegend("Sensor $sensor[$a]"); $graph->Add($lineplot[$a]); } } $graph->legend->Pos(0.03, 0.3, "right", "center"); $graph->xaxis->SetTickLabels($datax); $graph->xaxis->SetTextTickInterval($x_tick_diff); //$graph->xaxis->SetTextLabelInterval(2); $graph->img->SetMargin(50, 120, 30, 50); if (isset($computer)) $graph->title->Set($computer); $graph->xaxis->title->Set("°C"); //$graph->xaxis->SetLabelAngle(90); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->yaxis->SetColor("red"); $graph->yaxis->SetWeight(2); $graph->SetShadow(); // Display the graph $graph->Stroke(); ?>