WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
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 Index
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
Mobile Dev World

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 : a simple pie-chart in php3 (with gd)
Categories : PHP, Graphics, GD image library, Charts and Graphs Update Picture
knik -
Date : Jun 26th 2000
Grade : 2 of 5 (graded 15 times)
Viewed : 18401
File : pie.php3
Images : No Images for this code example.
Search : More code by knik -
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?php

// a simple pie-chart in php3 (with gd)
// (c)2000 knik@crosswinds.net
//
// usage: pie.php3?label=value&label=value&label=value&...
// ex.: pie.php3?label1=10&label2=15&label3=20
//
// code can be freely copied & modified


Header("Content-type: image/gif");

//init and create image:
$img_width = 320;
$img_height = 192;
$id = ImageCreate($img_width,$img_height);
$hcenter = ImageSX($id)/2;
$vcenter = ImageSY($id)/2;
//diameter:
$d = 160;

//define colors:
//there are 9 pie colors, same as in Excel
$black = ImageColorAllocate($id, 0, 0, 0);
$white = ImageColorAllocate($id, 255, 255, 255);
$pie_color[1] = ImageColorAllocate($id, 144, 151, 255);
$pie_color[2] = ImageColorAllocate($id, 144, 48, 96);
$pie_color[3] = ImageColorAllocate($id, 255, 255, 192);
$pie_color[4] = ImageColorAllocate($id, 207, 255, 255);
$pie_color[5] = ImageColorAllocate($id, 95, 0, 95);
$pie_color[6] = ImageColorAllocate($id, 255, 127, 127);
$pie_color[7] = ImageColorAllocate($id, 207, 255, 255);
$pie_color[8] = ImageColorAllocate($id, 0, 96, 192);
$pie_color[9] = ImageColorAllocate($id, 207, 200, 255);

//the white background will be transparent:
ImageFill($id, 0, 0, $white);
ImageColorTransparent($id, $white);

if (empty($argv)) {
//if no agruments are given than show the empty chart:
ImageArc($id, $hcenter, $vcenter, $d, $d, 0, 360, $black);
$idf = 3;
$hfw = ImageFontWidth($idf);
$vfw = ImageFontHeight($idf);
$string = "no args!";
$hpos = $hcenter - $hfw*strlen($string)/2;
$vpos = $vcenter - $vfw/2;
ImageString($id, $idf, $hpos, $vpos, $string, $black);
$string = "ex.: pie.php3?label1=10&label2=15&label3=20";
$hpos = $hcenter - $hfw*strlen($string)/2;
$vpos = ImageSY($id) - $vfw;
ImageString($id, $idf, $hpos, $vpos, $string, $black);
}
else {
$total = 0;
$n = 0;
//read the arguments into different arrays:
while (list($key, $val) = each($HTTP_GET_VARS)) {
$n++;
$label[$n] = $key;
$value[$n] = $val;
$total += $val;
$arc_rad[$n] = $total*2*pi(void);
$arc_dec[$n] = $total*360;
}
//the base:
$arc_rad[0] = 0;
$arc_dec[0] = 0;
//count the labels:
for ($i = 1; $i <= $n; $i++) {
$idf = 1;
$hfw = ImageFontWidth($idf);
$vfw = ImageFontHeight($idf);
//calculate the percents:
$perc[$i] = $value[$i]/$total;
$percstr[$i] = (string) number_format($perc[$i]*100,1)."%";
//label with percentage:
$label[$i] = $label[$i]." (".$percstr[$i].")";

//calculate the arc and line positions:
$arc_rad[$i] = $arc_rad[$i]/$total;
$arc_dec[$i] = $arc_dec[$i]/$total;
$hpos = Round($hcenter + ($d/2)*Sin($arc_rad[$i]));
$vpos = Round($vcenter + ($d/2)*Cos($arc_rad[$i]));
ImageLine($id, $hcenter, $vcenter, $hpos, $vpos, $black);
ImageArc($id, $hcenter, $vcenter, $d, $d, $arc_dec[$i-1], $arc_dec[$i], $black);

//calculate the positions for the labels:
$arc_rad_label = $arc_rad[$i-1] + 0.5*$perc[$i]*2*pi(void);
$hpos = $hcenter + 1.1*($d/2)*Sin($arc_rad_label);
$vpos = $vcenter + 1.1*($d/2)*Cos($arc_rad_label);
if (($arc_rad_label > 0.5*pi(void)) && ($arc_rad_label < 1.5*pi(void))) {
$vpos = $vpos - $vfw;
}
if ($arc_rad_label > pi(void)) {
$hpos = $hpos - $hfw*strlen($label[$i]);
}
//display the labels:
ImageString($id, $idf, $hpos, $vpos, $label[$i], $black);
}
//fill the parts with their colors:
for ($i = 1; $i <= $n; $i++) {
$arc_rad_label = $arc_rad[$i-1] + 0.5*$perc[$i]*2*pi(void);
$hpos = $hcenter + 0.8*($d/2)*Sin($arc_rad_label);
$vpos = $vcenter + 0.8*($d/2)*Cos($arc_rad_label);
ImageFillToBorder($id, $hpos, $vpos, $black, $pie_color[$i]);
}
}

//and finally:
ImageGif($id);
ImageDestroy($id);

?>



Display a bar chart based on random values.
Categories : Graphics, PHP, GD image library, Charts and Graphs
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
PHP interface class to the eBusiness Charts generatation remote service.
Categories : PHP, PHP Classes, Graphics, Charts and Graphs
Advanced Image WaterMarker
Categories : PHP, PHP Classes, GD image library, Graphics, Object Oriented
Annual Bar Chart
Categories : Graphics, PHP, 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
Simple PHP Bar Graph using GD library
Categories : PHP, GD image library, Graphics, Arrays
Line graphics generation library written in PHP + GD library (spanish comments)
Categories : PHP, Graphics, GD image library
Image Generation Class ( PNG Format )
Categories : PHP, GD image library, PHP Classes, Graphics
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
PHP Image Compression using GD library
Categories : PHP, Compression, GD image library, Graphics
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
CAPTCHA[Image verification]
Categories : PHP, Security, GD image library, Graphics, Sessions
imageMarker v 3.00 with new advanced features
Categories : PHP, PHP Classes, Graphics, GD image library
3dLib - a class for drawing in 3D space. Supported functions: Line, SetPixel, Polygon, FilledPolygon, etc. 3dChart() function has been added for one-call drawing of 3d charts. Support of mostly used 3d-transformations.
Categories : Graphics, Math., PHP Classes, PHP, Charts and Graphs