PHP and MySQL Code

Start typing to search for PHP and MySQL Code Snippets and Articles Search

Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
Title : Simple PHP Bar Graph using GD library
Categories : PHP, GD image library, Graphics, Arrays Click here to Update Your Picture
Vijit Patil
Date : Apr 25th 2007
Grade : 3 of 5 (graded 10 times)
Viewed : 49019
File :
Images : Image 1 , Image 2
Search : More code by Vijit Patil
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 

In this example we are going to draw a simple Bar graph. Take a school for exmaple. We are going to draw a graph for week days and the total number of student that come to school.

First of all we declare two arrays. The first for the student and the second for week days. Then we calculate the maximal number of student. On the basis of that number we are going to calculate the percentage length of the other bar graphs.

Using the php imagerectangle() function we draw the graph.
We use imagestring() to display our label and message.

You need the GD Library installed.

<meta http-equiv="Content-Language" content="en-us">
<title>Simple Bar Graph .. by viji patil</title>
// read the post data
$data = array('100','200','300','400','500','350','270');
$x_fld = array('Sun','Mon','Tue','Wen','Thu','Fir','Sat');
$max = 0;
        for (
          if (
$data[$i] > $max)$max=$data[$i];  // find the largest data
$im = imagecreate(320,255); // width , height px

$white = imagecolorallocate($im,255,255,255); // allocate some color from RGB components remeber Physics
$black = imagecolorallocate($im,0,0,0);   //
$red = imagecolorallocate($im,255,0,0);   //
$green = imagecolorallocate($im,0,255,0); //
$blue = imagecolorallocate($im,0,0,255);  //
        // create background box
        //imagerectangle($im, 1, 1, 319, 239, $black);
        //draw X, Y Co-Ordinate
imageline($im, 10, 5, 10, 230, $blue );
imageline($im, 10, 230, 300, 230, $blue );
//Print X, Y
imagestring($im,5,100,50,"Simple Graph",$red);
imagestring($im,5,125,75,"by Vijit",$green);

// what next draw the bars
$x = 15;    // bar x1 position
$y = 230;    // bar $y1 position
$x_width = 20// width of bars
$y_ht = 0; // height of bars, will be calculated later
        // get into some meat now, cheese for vegetarians;
for ($i=0;$i<7;$i++){
$y_ht = ($data[$i]/$max)* 100;    // no validation so check if $max = 0 later;
imagestring( $im,2,$x-1,$y+1,$x_fld[$i],$black);
imagestring( $im,2,$x-1,$y+10,$data[$i],$black);
$x += ($x_width+20);   // 20 is diff between two bars;
imagejpeg( $im, "graph.jpeg", 90);
"<img src='graph.jpeg'><p></p>";

crop and resize image class using gd library function
Categories : PHP, PHP Classes, GD image library, Graphics
Simple class that uses GD to draw pie charts. After the class definition there's some sample code to demonstrate how you use the class.
Categories : Graphics, PHP, PHP Classes, GD image library, Charts and Graphs
PHPDRAW, the php wannabe Photoshop ;-)
Categories : PHP, PHP Classes, GD image library, Arrays
Create Thumbnails - resize an image - jpeg, jpg, gif, png to the specifed width and height in proportion without loosing out on pixcel quality.
Categories : PHP, GD image library, Graphics
Simple way of scaling any image to fit either given width or height.
Categories : PHP, Graphics, Arrays
Create a Thumbnail Using PHP, GD and Exif
Categories : PHP, Graphics, Exif, GD image library
PHP Email image generator - hide your email from bots - using the GD Library
Categories : PHP, Graphics, GD image library, Beginner Guides
Advanced Image WaterMarker
Categories : PHP, PHP Classes, GD image library, Graphics, Object Oriented
Image Generation Class ( PNG Format )
Categories : PHP, GD image library, PHP Classes, Graphics
PHP Image Compression using GD library
Categories : PHP, Compression, GD image library, Graphics
Line graphics generation library written in PHP + GD library (spanish comments)
Categories : PHP, Graphics, GD image library
a simple pie-chart in php3 (with gd)
Categories : PHP, Graphics, GD image library, Charts and Graphs
A captcha image allows you to prevent spam posting when users reload the page and stop bots from submitting forms automatically. This version allows you to use your own fonts (.ttf) to show the text.
Categories : PHP, Security, Graphics, GD image library
EasyPhpThumbnail Class - The EasyPhpThumbnail class allows you to generate thumbnails and handle image manipulation for GIF, JPG and PNG on-the-fly.
Categories : PHP, PHP Classes, Object Oriented, Graphics, GD image library
How to display any array in several rows and columns of a table. Not just in one column or in alternate rows. This example shows a nice color table generated with PHP, but can be used with any array values(e.g. Database)
Categories : Arrays, PHP, Miscellaneous, Beginner Guides, Graphics