hello im stuck and i need your help please
Problem:
i have a template class for a graph and i want to import information to the template to create multiple graphs with different statistics. here is my code:
the graph class files is:
essentialy i have to create multiple instances of the graph class and I think its something to do with constructors and stuff but im not sure.
any help appreciated.
slh
Problem:
i have a template class for a graph and i want to import information to the template to create multiple graphs with different statistics. here is my code:
PHP Code:
<?PHP
//get all class files required
require "dbConnect.php";
$conn = new dbConnect();
require "getData_cls.php";
$myData = new data();
require "shape_cls.php";
$displayGraph = new shape();
//get data from classes
$connection = $conn->connect();
$countMen = $myData->getMen($connection);
$countWomen = $myData->getWomen($connection);
$countStirAttendeeYes = $myData->getStirAttendeeYes($connection);
$countStirAttendeeNo = $myData->getStirAttendeeNo($connection);
//describe data in context of graph
if($countMen && $countWomen){
$displayGraph->dataAlpha = $countMen;
$displayGraph->dataBeta = $countWomen;
$displayGraph->title = 'Gender';
$displayGraph->dataKeyAlpha = 'Men';
$displayGraph->dataKeyBeta = 'Women';
$displayGraph->graph();
}
if($countStirAttendeeYes && $countStirAttendeeNo){
$displayGraph->dataAlpha = $countStirAttendeeYes;
$displayGraph->dataBeta = $countStirAttendeeNo;
$displayGraph->title = 'Stirling Uni Attendees';
$displayGraph->dataKeyAlpha = 'Yes';
$displayGraph->dataKeyBeta = 'No';
$displayGraph->graph();
}
?>
PHP Code:
<?PHP
class shape{
var $dataAlpha;
var $dataBeta;
var $title;
var $dataKeyAlpha;
var $dataKeyBeta;
/**************************************************************************
function graph
***************************************************************************/
function graph(){
$dataAlpha = trim($this->dataAlpha);
$dataBeta = trim($this->dataBeta);
$title = trim($this->title);
$dataKeyAlpha = trim($this->dataKeyAlpha);
$dataKeyBeta = trim($this->dataKeyBeta);
/*for the y axis when describing shapes use the height-value to make it easier to work out*/
$height = 150;
$width = 200;
$countTotal = $dataAlpha + $dataBeta;
$perCentAlpha = floor($dataAlpha / $countTotal * 100);
$perCentBeta = floor($dataBeta / $countTotal * 100);
$titlePos = $width-190;
$image = imagecreate($width,$height);
$grey = ImageColorAllocate($image,210,210,210);
$blue = ImageColorAllocate($image,0,130,255);
$pink = ImageColorAllocate($image,255,0,240);
$white = ImageColorAllocate($image,255,255,255);
$black = ImageColorAllocate($image,0,0,0);
imageString($image, 5, $titlePos, $height-140, $title, $black); //title
imageFilledRectangle($image,10,$height-$perCentAlpha,30,$height-10,$blue); //bar to represent men
imageFilledRectangle($image,40,$height-$perCentBeta,60,$height-10,$pink); //bar to represent women
imageFilledRectangle($image,8,$height-100,9,$height-0,$black); //y axis
imageFilledRectangle($image,0,$height-9,70,$height-8,$black); //x axis
imageString($image, 5, 100, $height-50, "$dataKeyAlpha".': '."$perCentAlpha".'%', $blue); //info
imageString($image, 5, 100, $height-35, "$dataKeyBeta".': '."$perCentBeta".'%', $pink); //info
header ("Content-type: image/png");
ImagePng($image);
ImageDestroy($image);
}//end graph function
}//end class
?>
any help appreciated.
slh
Comment