Create Bar Chart Using GD library

GD library is useful for creating 2D charts.

Graph Image

Copy and paste this code in your php file
<!–/ By Raghwendra$graphValues=array(50,80,23,11,190,120,50,80,111,210,55);
$graphValues_city=array(‘mumbai’,’delhi’,’channai’,’banglore’,’chandigarh’,
‘surat’,’kanpur’,’patna’,’hyderabad’,’jammu’,’lacknow’);
header(“Content-type: image/png”);
$imgWidth=1000;
$imgHeight=280;
// Create image and define colors
$image=imagecreate($imgWidth, $imgHeight);
$colorWhite=imagecolorallocate($image, 255, 255, 255);
$colorGrey=imagecolorallocate($image, 192, 192, 192);
$colorBlue=imagecolorallocate($image, 0, 0, 255);
// Create border around image
imageline($image, 0, 0, 0, 250, $colorGrey);
imageline($image, 0, 249, 1000, 249, $colorGrey);
for ($i=0; $i<11; $i++)
{
imagefilledrectangle($image, ($i*80)+10, (250-$graphValues[$i])+1, (($i+1)*80)-20, 248, $colorBlue);
imagefttext( $image, 10, 0, ($i*80)+strlen($graphValues_city[$i]),270, $colorGrey, ‘trebuc.ttf’, $graphValues_city[$i], array(‘lineheight’=>2.0) );
imagefttext( $image, 10, 0, ($i*80)+20,244-$graphValues[$i], $colorGrey, ‘trebuc.ttf’, $graphValues[$i], array(‘lineheight’=>2.0) );
}
imagepng($image);
imagedestroy($image);
//imagefilledrectangle($image, $i*25, (250-$graphValues[$i]), ($i+1)*25, 250, $colorBlue);
//imagefilledrectangle($image, ($i*50)-10, (250-$graphValues[$i])+1, (($i+1)*50)-5, 248, $colorBlue);
?>

rangnath

Share
Published by
rangnath

Recent Posts

Benefits of Hiring Magento Custom Development in 2024

Choosing the perfect Magento Custom Development is quite a challenging task. As being a technical…

2 months ago

How to Choose the Best React JS Development Company in 2024

Usually finding a perfect React JS Development Company is a difficult task, but to simplify…

3 months ago

Tips to Choose Best Shopify Website Development Services

Have you ever worried about things that you should consider while choosing Shopify Website Development…

4 months ago

How Can SEO Company in India Help My Startup Grow?

Have you ever thought that is it important to hire an SEO Company in India…

4 months ago

Top Benefits of Magento Custom Development Services

You can easily grow your e-commerce business with Magento Custom Development Services from Raghwandra. Our…

5 months ago

Raghwendra The Best React JS Development Company

Every person who has an online business always wants seamless web development and smooth performance.…

5 months ago