WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
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
PHPClasses
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.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
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 : 45602
File : 4619.zip
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.


<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>Simple Bar Graph .. by viji patil</title>
</head>
<body>
<?php
   
       
// 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 (
$i=0;$i<7;$i++){
          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,3,15,5,"Students",$black);
       
imagestring($im,3,280,240,"Days",$black);
       
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;
         
imagerectangle($im,$x,$y,$x+$x_width,($y-$y_ht),$red);
         
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);
       
imagedestroy($im);
        echo
"<img src='graph.jpeg'><p></p>";
 
?>
</body>
</html>



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
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
a simple pie-chart in php3 (with gd)
Categories : PHP, Graphics, GD image library, Charts and Graphs
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 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
imageMarker v 3.00 with new advanced features
Categories : PHP, PHP Classes, Graphics, GD image library
Display a bar chart based on random values.
Categories : Graphics, PHP, GD image library, Charts and Graphs
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
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