Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bar Graphs without GD Lib

Status
Not open for further replies.

4x4uk

Technical User
Apr 30, 2002
381
GB
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=&quot;1.5&quot;;

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

$value1=&quot;10&quot;;
$value2=&quot;25&quot;;
$value3=&quot;80&quot;;
$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&quot;<html><head></head><body>
<table border=\&quot;0\&quot;><tr>
<td><b>Value 1</b></td><td width=\&quot;150px\&quot;></td><td align=\&quot;center\&quot;><b>%</b></td><td><b>Count</b></td>
</tr>
<tr><td>Value 1</td>
<td>
<img src=\&quot;bar.gif\&quot; width=\&quot;$bar1\&quot; height=\&quot;10\&quot; hspace=\&quot;0\&quot; vspace=\&quot;0\&quot; border=\&quot;0\&quot; align=\&quot;top\&quot;>
</td><td align=\&quot;right\&quot;>$pcv1</td><td align=\&quot;right\&quot;>$value1</td>
</tr>
<tr>
<td>Value 2</td><td>
<img src=\&quot;bar.gif\&quot; width=\&quot;$bar2\&quot; height=\&quot;10\&quot; hspace=\&quot;0\&quot; vspace=\&quot;0\&quot; border=\&quot;0\&quot; align=\&quot;top\&quot;>
</td><td align=\&quot;right\&quot;>$pcv2</td><td align=\&quot;right\&quot;>$value2</td>
</tr>
<tr>
<td>Value 3</td><td>
<img src=\&quot;bar.gif\&quot; width=\&quot;$bar3\&quot; height=\&quot;10\&quot; hspace=\&quot;0\&quot; vspace=\&quot;0\&quot; border=\&quot;0\&quot; align=\&quot;top\&quot;>
</td><td align=\&quot;right\&quot;>$pcv3</td><td align=\&quot;right\&quot;>$value3</td>
</tr></table></body></html>&quot;;
?> It's not a lie if you believe it!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top