Page 1 of 1

problem

Posted: Mon Jul 30, 2007 5:13 am
by sandy1028
Hi,

Facing problem in plotting when the fixed width and heigth is given






Code: Select all

$graphValues=array($avg,$max); 

// Define .PNG image 
header("Content-type: image/png"); 
$imgWidth=50; 
$imgHeight=15; 

// Create image and define colors 
$image=imagecreate($imgWidth, $imgHeight); 
$colorWhite=imagecolorallocate($image, 0, 255, 255); 
$colorGrey=imagecolorallocate($image, 192, 192, 192); 
$colorBlue=imagecolorallocate($image, 0, 0, 255); 
$colorred=imagecolorallocate($image, 255, 0, 0); 


imagefill($image, 0, 0, $colorGrey); 

$avg_val= ($imgWidth * $avg)/$max; 


//verticle lines 
imageline($image, $i*50, 0, $i*50, 50, $colorGrey); 
imagefilledrectangle($image, 0 ,0,$avg_val,$imgWidth,$colorred); 
//Horizontal lines 

//destroy the image 
imagepng($image); 
imagedestroy($image);

Posted: Mon Jul 30, 2007 5:20 am
by onion2k
You say you're facing a problem but you don't explain what it is. How do you expect anyone to help?

Posted: Mon Jul 30, 2007 5:47 am
by sandy1028
onion2k wrote:You say you're facing a problem but you don't explain what it is. How do you expect anyone to help?

I am facing problem taking large values in the array and ploting against the fixed width and heigth of the image...

I tried plotting like ($avg/$max)*50

But I feel it is not correct

Posted: Mon Jul 30, 2007 6:24 am
by onion2k
The size of the vertical axis needed to be scaled against the size of the image. The most straightforward way to achieve that is with a percentage...

Code: Select all

$image_height = 50; //The height of the image in pixels.
$max_value = 100; //The maximum value of the graph.
$real_value = 50; //The value you want to plot.

//Take the ratio of the real value to the maximum (etc 50/100 = 0.5), and multiply it by the image height.
$plot_height = ($real_value/$max_value) * $image_height;

//Plot from 0,0 to $imgWidth,$image_value.
imagefilledrectangle($image, 0, 0, $imgWidth, $plot_height, $colorRed);
You might also find that with 0,0 being the top left your graph is upside down.

Posted: Mon Jul 30, 2007 7:00 am
by sandy1028
onion2k wrote:The size of the vertical axis needed to be scaled against the size of the image. The most straightforward way to achieve that is with a percentage...

Code: Select all

$image_height = 50; //The height of the image in pixels.
$max_value = 100; //The maximum value of the graph.
$real_value = 50; //The value you want to plot.

//Take the ratio of the real value to the maximum (etc 50/100 = 0.5), and multiply it by the image height.
$plot_height = ($real_value/$max_value) * $image_height;

//Plot from 0,0 to $imgWidth,$image_value.
imagefilledrectangle($image, 0, 0, $imgWidth, $plot_height, $colorRed);
You might also find that with 0,0 being the top left your graph is upside down.

Hi,

Thanks for the reply....

Is there any way to plot without percentage....
$imgHeight=15
$imgWidth=50
$avg=75
$max=333

How to divide the width based on the max value into ten parts and then plot........
How can we add the imageString to it

Posted: Mon Jul 30, 2007 8:20 am
by onion2k
Is there any way to plot without percentage....
$imgHeight=15
$imgWidth=50
$avg=75
$max=333
There's plenty of alternatives. Unless you state what you want then there's no way to suggest something though.
How to divide the width based on the max value into ten parts and then plot........
No idea what you mean.
How can we add the imageString to it
Don't understand the question here either. What string?

Posted: Tue Jul 31, 2007 10:27 pm
by sandy1028
onion2k wrote:
Is there any way to plot without percentage....
$imgHeight=15
$imgWidth=50
$avg=75
$max=333
There's plenty of alternatives. Unless you state what you want then there's no way to suggest something though.
How to divide the width based on the max value into ten parts and then plot........
No idea what you mean.
How can we add the imageString to it
Don't understand the question here either. What string?
Mark the $max and $avg value in the rectangle. Write the values externally to rectangle