Total members 11894 |It is currently Sun Nov 24, 2024 9:43 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Code:
<?php
header
("Content-type: image/gif");
$cells = array ( liked=>200, hated=>400, indifferent=>900 );
$max = max( $cells );
$total = count ( $cells );
$totalwidth = 300;
$totalheight = 200;
$xgutter = 20; // left/right margin
$ygutter = 20; // top/bottom margin
$internalgap = 10; // space between cells
$bottomspace = 30; // gap at the bottom (in addition to margin)
$font = "ARIALBD.TTF";
$graphCanX = ( $totalwidth - $xgutter*2 );
$graphCanY = ( $totalheight - $ygutter*2 - $bottomspace );// starting draw position x - axis
$posX = $xgutter; // starting draw pos - y -  axis
$posY = $totalheight - $ygutter - $bottomspace;
$cellwidth = (int) (( $graphCanX - ( $internalgap * ( $total-1 ) )) / $total) ;
$textsize = (int)($bottomspace);
// adjust font size
while ( list( $key, $val ) = each ( $cells ) )
    {
     while (
1 )
        {
        
$box = ImageTTFbBox( $textsize, 0, $font, $key );
        
$textWidth = abs( $box[2] );
        if (
$textWidth < $cellwidth )
            break;
        
$textsize--;
        }
    }
$image = imagecreate( $totalwidth, $totalheight );
$red = ImageColorAllocate($image, 255, 0, 0);
$blue = ImageColorAllocate($image, 0, 0, 255 );
$black = ImageColorAllocate($image, 0, 0, 0 );
$grey = ImageColorAllocate($image, 100, 100, 100 );
reset ($cells);
while ( list(
$key, $val ) = each ( $cells ) )
     {
     
$cellheight = (int) (($val/$max) * $graphCanY);
     
$center = (int)($posX+($cellwidth/2));
    
imagefilledrectangle( $image, $posX, ($posY-$cellheight), ($posX+$cellwidth), $posY, $blue );
     
$box = ImageTTFbBox( $textsize, 0, $font, $key );
     
$tw = $box[2];
     
ImageTTFText(    $image, $textsize, 0, ($center-($tw/2)),
             (
$totalheight-$ygutter), $black, $font, $key );
     
$posX += ( $cellwidth + $internalgap);
     }
imagegif( $image );
?>
<!--/*
Code Revised from



Sam's Teach Yourself Php, Mysql and Apache in 24 Hours
(Sams Teach Yourself S.) (Paperback)
by Julie C. Meloni

# Paperback: 616 pages
# Publisher: Sams (1 Jan 2004)
# Language English
# ISBN: 0672326205

-->




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : make Dynamic Bar Chart by php
 How to generate dynamic 3d pie chart in php???     -  
 Dynamic Domain Name System (Dynamic DNS )     -  
 Draw pie chart php     -  
 Chart enhancement (upgrading to 3D preferable)     -  
 Print a chart that shows how many number in each range     -  
 How do you 301 redirect a dynamic URL?     -  
 Dynamic Array Allocation     -  
 DYNAMIC DATES IN MYSQL     -  
 how to implement Dynamic DDS (Domain Name System)     -  
 dynamic crystal report generation     -  



Topic Tags

PHP Graphics
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com