{"id":15,"date":"2011-07-07T03:46:25","date_gmt":"2011-07-07T03:46:25","guid":{"rendered":"http:\/\/blog.raghwendra.com\/?p=15"},"modified":"2011-07-07T03:47:53","modified_gmt":"2011-07-07T03:47:53","slug":"create-bar-chart-using-gd-library","status":"publish","type":"post","link":"https:\/\/www.raghwendra.com\/blog\/create-bar-chart-using-gd-library\/","title":{"rendered":"Create Bar Chart Using GD library"},"content":{"rendered":"<p>GD library is useful for creating 2D charts.<!--more--><\/p>\n<p>Graph Image<br \/>\n<img fetchpriority=\"high\" decoding=\"async\" src=\"http:\/\/raghwendra.com\/gdchart.php\" height=\"280\" width=\"400\" \/><\/p>\n<p>Copy and paste this code in your php file<br \/>\n&lt;!&#8211;\/ By Raghwendra$graphValues=array(50,80,23,11,190,120,50,80,111,210,55);<br \/>\n$graphValues_city=array(&#8216;mumbai&#8217;,&#8217;delhi&#8217;,&#8217;channai&#8217;,&#8217;banglore&#8217;,&#8217;chandigarh&#8217;,<br \/>\n&#8216;surat&#8217;,&#8217;kanpur&#8217;,&#8217;patna&#8217;,&#8217;hyderabad&#8217;,&#8217;jammu&#8217;,&#8217;lacknow&#8217;);<br \/>\nheader(&#8220;Content-type: image\/png&#8221;);<br \/>\n$imgWidth=1000;<br \/>\n$imgHeight=280;<br \/>\n\/\/ Create image and define colors<br \/>\n$image=imagecreate($imgWidth, $imgHeight);<br \/>\n$colorWhite=imagecolorallocate($image, 255, 255, 255);<br \/>\n$colorGrey=imagecolorallocate($image, 192, 192, 192);<br \/>\n$colorBlue=imagecolorallocate($image, 0, 0, 255);<br \/>\n\/\/ Create border around image<br \/>\nimageline($image, 0, 0, 0, 250, $colorGrey);<br \/>\nimageline($image, 0, 249, 1000, 249, $colorGrey);<br \/>\nfor ($i=0; $i&lt;11; $i++)<br \/>\n{<br \/>\nimagefilledrectangle($image, ($i*80)+10, (250-$graphValues[$i])+1, (($i+1)*80)-20, 248, $colorBlue);<br \/>\nimagefttext( $image, 10, 0, ($i*80)+strlen($graphValues_city[$i]),270, $colorGrey, &#8216;trebuc.ttf&#8217;, $graphValues_city[$i], array(&#8216;lineheight&#8217;=&gt;2.0) );<br \/>\nimagefttext( $image, 10, 0, ($i*80)+20,244-$graphValues[$i], $colorGrey, &#8216;trebuc.ttf&#8217;, $graphValues[$i], array(&#8216;lineheight&#8217;=&gt;2.0) );<br \/>\n}<br \/>\nimagepng($image);<br \/>\nimagedestroy($image);<br \/>\n\/\/imagefilledrectangle($image, $i*25, (250-$graphValues[$i]), ($i+1)*25, 250, $colorBlue);<br \/>\n\/\/imagefilledrectangle($image, ($i*50)-10, (250-$graphValues[$i])+1, (($i+1)*50)-5, 248, $colorBlue);<br \/>\n?&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GD library is useful for creating 2D charts.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,6],"tags":[],"class_list":["post-15","post","type-post","status-publish","format-standard","hentry","category-content-management-system","category-open-source-php","entry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.raghwendra.com\/blog\/wp-json\/wp\/v2\/posts\/15","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.raghwendra.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.raghwendra.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.raghwendra.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.raghwendra.com\/blog\/wp-json\/wp\/v2\/comments?post=15"}],"version-history":[{"count":0,"href":"https:\/\/www.raghwendra.com\/blog\/wp-json\/wp\/v2\/posts\/15\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.raghwendra.com\/blog\/wp-json\/wp\/v2\/media?parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.raghwendra.com\/blog\/wp-json\/wp\/v2\/categories?post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.raghwendra.com\/blog\/wp-json\/wp\/v2\/tags?post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}