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

Boost Your Store’s Conversions: E-Commerce CRO Checklist

If your D2C store gets steady traffic but sales still feel harder than they should,…

5 days ago

AI Image Prompt Engineering: A 5-Level Framework for Master Prompts

Generating a high-quality AI image isn't about writing a long paragraph of text. AI image…

2 weeks ago

Smart Product Filters: How to Stop Shoppers Hitting Dead Ends on Your Online Store

Smart product filters help shoppers find products fast. But only when they are built correctly.…

2 months ago

Benefits of Hiring Magento Custom Development in 2024

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

3 years 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 years ago

Tips to Choose Best Shopify Website Development Services

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

3 years ago