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 : 49842
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>";

imageMarker v 3.00 with new advanced features
Categories : PHP, PHP Classes, Graphics, GD image library
CAPTCHA[Image verification]
Categories : PHP, Security, GD image library, Graphics, Sessions
This script will read all images from a folder and read the files into an array. It uses rand() to get a random number. It will display a random image from the image folder given.
Categories : PHP, Arrays, Graphics, Filesystem
Display a bar chart based on random values.
Categories : Graphics, PHP, GD image library, Charts and Graphs
HTML_Graphs uses PHP to provide a consistent interface for creating HTML based charts. The user of the class sets up arrays that are passed to html_graph() which then takes care of all the messy HTML layout.
Categories : Graphics, Arrays, PHP, PHP Classes, Charts and Graphs
Generate image with random number (CAPTCHA)
Categories : PHP, GD image library, Graphics, Security
crop and resize image class using gd library function
Categories : PHP, PHP Classes, GD image library, Graphics
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
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
a simple pie-chart in php3 (with gd)
Categories : PHP, Graphics, GD image library, Charts and Graphs
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