Location: PHPKode > projects > PACSPulse > pacspulse/chartsergen.php
<?php


/* 
PAC Pulse (PACS Perfomance optimization tool)
Copyright (C) 2001 Medical College of Wisconsin

This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

include("phplot.php");
include ("globalvars.php");
$graph = new PHPlot(500,300);
switch ($Q)
{
	case 1:
	$sql_command = "select week(timestamp),format(sum(size)/1000,0),format(avg(rate)/1000,2)";
	$sql_command .= " from test group by week(timestamp)";
	$graph->SetXLabel('Week Number (0-51)');
	$graph->SetYLabel('Volume of Data (MB)');
	$graph->SetTitle('Volume and Performance Analysis by Week');
	break;
	case 2:
	$sql_command = "select hour(timestamp),format(sum(size)/1000,0),format(avg(rate)/1000,2)";
	$sql_command .= " from test group by hour(timestamp)";
	$graph->SetXLabel('Hour of the Day (0-23)');
	$graph->SetYLabel('Volume of Data (GB)');
	$graph->SetTitle('Volume and Performance Analysis by Hour');
	break;
	case 3:
	$sql_command = "select typeMod,format(sum(size)/1000,0),format(avg(rate)/1000,2)";
	$sql_command .= " from test group by typeMod";
	$graph->SetXLabel('Modality');
	$graph->SetYLabel('Volume of Data (GB)');
	$graph->SetTitle('Volume and Performance Analysis by Modality');
	break;
	case 4:
	$sql_command = "select dayofweek(timestamp),format(sum(size)/1000,0),format(avg(rate)/1000,2)";
	$sql_command .= " from test group by dayofweek(timestamp)";
	$graph->SetXLabel('Day of the Week');
	$graph->SetYLabel('Volume of Data (GB)');
	$graph->SetTitle('Volume and Performance Analysis by day of the week');
	break;
	case 5:
	$sql_command = "select dayofmonth(timestamp),format(sum(size)/1000,0),format(avg(rate)/1000,2)";
	$sql_command .= " from test group by dayofmonth(timestamp)";
	$graph->SetXLabel('Day of the month (1-31)');
	$graph->SetYLabel('Volume of Data (GB)');
	$graph->SetTitle('Volume and Performance Analysis by day of month');
	break;
	case 7:
	$sql_command = "select format((rate/500),0)*.5,count(size),count(size) from test   group by format((rate/500),0)*500";
	$graph->SetXLabel('Performance (MB/S)');
	$graph->SetYLabel('Relative Frequency');
	$graph->SetTitle('Performance Histogram');
	break;
	case 6:
	$sql_command = "select numAssoc,count(numAssoc),format(avg(rate)/1000,2) from test group by numAssoc order by numAssoc";
	$graph->SetXLabel('Number of Simultaneous Associations');
	$graph->SetYLabel('Number of Connections');
	$graph->SetTitle('Server Loading Analysis');
	break;


}

//Define the object
$graph->SetIsInline("1");
$graph->SetPrintImage(0);
$db = mysql_select_db("pulsetest", $connection) or die ("Couldn't connect to DB Radtracker");
$sql_result = mysql_query($sql_command,$connection) or die (mysql_error());
while ($row = mysql_fetch_array($sql_result)) {
	$example_data[]=array($row[0],$row[1]);
	$example_data2[]=array($row[0],$row[2]);
}

//Set some data
$graph->SetDataValues($example_data);
$graph->SetBackgroundColor("white");
$graph->SetPlotType('bars');
$graph->SetShading(2);
$graph->SetPrecisionY("0");
$graph->SetXDataLabelMaxlength(4);
//Draw it
$graph->DrawGraph();

if ($Q<7)
{
$graph->SetDataValues($example_data2);
$graph->SetDataColors(array("red"),array("green"));
$arrsize=sizeof($example_data2);
$graph->SetDrawXDataLabels(0); //We already got them in the first graph
$graph->SetPlotAreaWorld(0,0,$arrsize,6); //New Plot Area
$graph->SetLegend(array('Performance (MB/S)')); //Lets add a second legend
$graph->DrawLegend(80,65,'');

//Set Params of another Y Axis
$graph->SetVertTickPosition('yaxis');
$graph->SetYAxisPosition($arrsize+1.5);
$graph->SetPrecisionY("1");
$graph->SetTickColor('red');
$graph->SetTextColor('red');
$graph->SetGridColor('red');
$graph->DrawYAxis();
$graph->SetFileFormat('JPEG');

//Draw the New data over the first graph
$graph->DrawLines();
$graph->DrawDots();
}
$graph->PrintImage();

?>
Return current item: PACSPulse