Hi all,
I have got a problem with plotting bar graph using GD. I am learning GD now.
I have written the code for basic bar graph with one bar. What I need is, scale on Y-axis i.e. divisions on y-axis like 500,1000,1500 upto value which I have mentioned in $max variable which in my case is 4000.
Here is the code
Please give me some idea regarding this.
With regards
I have got a problem with plotting bar graph using GD. I am learning GD now.
I have written the code for basic bar graph with one bar. What I need is, scale on Y-axis i.e. divisions on y-axis like 500,1000,1500 upto value which I have mentioned in $max variable which in my case is 4000.
Here is the code
Code:
<?php
header("Content-type: image/jpeg");
$data = '1000';
$max = '4000';
$height = 255;
$width = 320;
$im = imagecreate($width,$height); // width , height px
$white = imagecolorallocate($im,255,255,255);
$black = imagecolorallocate($im,0,0,0);
$red = imagecolorallocate($im,255,0,0);
imageline($im, 10, 5, 10, 230, $black);
imageline($im, 10, 230, 300, 230, $black);
$x = 15;
$y = 230;
$x_width = 20;
$y_ht = 0;
$y_ht = ($data/$max)* $height;
imagerectangle($im,$x,$y,$x+$x_width,($y-$y_ht),$red);
imagestring( $im,2,$x-1,$y+10,$data,$black);
$x += ($x_width+20);
imagejpeg($im);
?>
With regards
Comment