×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

PHP and Ghraphics

Creating Bar graphs without GD Lib by 4x4uk
Posted: 16 Feb 03

If you can't or don't want to install GD Lib but still want to be able to manipulate images then this may be of interest to you. Particularly if you want to produce some simple bar graphs as I did.

First of all create a 2*10 pixel gif image (called bar.gif in this eaxmple)
then have a look at the script below and modify it to suit your own needs

<?php
// set the graphic scaling value
// use this to increase the size of the graphics
$scale="1.5";

// Use your own values here ie results from mysql query etc

$value1="10";
$value2="25";
$value3="80";
$total=($value1+$value2+$value3);

//Calculate Value as a pecentage with 1 decimal place showing
            
            $pcv1=round($value1/$total*100,1);
            $pcv2=round($value2/$total*100,1);
            $pcv3=round($value3/$total*100,1);

// Multiply Percentage value by Graphic scaling value
// Not totally necessary but this gives a level of
// control over the final graph size    
            
            $bar1=$pcv1*$scale;
            $bar2=$pcv2*$scale;
            $bar3=$pcv3*$scale;
            
// Output the data

echo"<html><head></head><body>
<table border=\"0\"><tr>
<td><b>Value 1</b></td><td width=\"150px\"></td><td align=\"center\"><b>%</b></td><td><b>Count</b></td>
</tr>
<tr><td>Value 1</td>
<td>
<img src=\"bar.gif\" width=\"$bar1\" height=\"10\" hspace=\"0\" vspace=\"0\" border=\"0\" align=\"top\">
</td><td align=\"right\">$pcv1</td><td align=\"right\">$value1</td>
</tr>
<tr>
<td>Value 2</td><td>
<img src=\"bar.gif\" width=\"$bar2\" height=\"10\" hspace=\"0\" vspace=\"0\" border=\"0\" align=\"top\">
</td><td align=\"right\">$pcv2</td><td align=\"right\">$value2</td>
</tr>
<tr>
<td>Value 3</td><td>
<img src=\"bar.gif\" width=\"$bar3\" height=\"10\" hspace=\"0\" vspace=\"0\" border=\"0\" align=\"top\">
</td><td align=\"right\">$pcv3</td><td align=\"right\">$value3</td>
</tr></table></body></html>";
?>

Back to PHP FAQ Index
Back to PHP Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close