NamePros.Com (http://www.namepros.com/)
-   CODE (http://www.namepros.com/code/)
-   -   Graphs with PHP (http://www.namepros.com/code/248186-graphs-with-php.html)

Barrucadu 10-17-2006 09:59 AM

Graphs with PHP
 
This may be simple but it took me a while to figure out, you will need a 1x1 png image for your graph's background

PHP Code:
//Sample Graph
$graph[0] = 5;
$graph[1] = 8;
$graph[2] = 1;
$graph[3] = 52;

//How much to scale the graph up (use a decimal to scale down)
$scale = 2;

//Code Starts Here
echo '<span style="font-family:\'Courier New\', Courier;">';
    
$i=1;
foreach(
$graph as $point){
     
$point = $point * $scale;
     if(
$i < count($graph)){
          echo
'<img style="border-top:1px solid #000000;border-left:1px solid #000000;border-bottom:1px solid #000000;" src="graph.png" height="'.$point.'" width="40px"/>';
     }else{
          echo
'<img style="border:1px solid #000000;" src="graph.png" height="'.$point.'" width="40px"/>';
     }
}
    
echo
'<br/>';
    
foreach(
$graph as $point){
     if(
$point <= 9){
          echo
$point.'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
     }elseif(
$point <= 99){
          echo
$day['income'].'&nbsp;&nbsp;&nbsp;&nbsp;';
     }elseif(
$day['income'] <= 999){
          echo
$day['income'].'&nbsp;&nbsp;&nbsp;';
     }
}
echo
'</span>';

-Ray- 10-17-2006 10:24 AM

nice little script mate....

THis would make an excellent include for a ipn script im writing....

rep +

Barrucadu 10-17-2006 12:05 PM

Originally Posted by templaterave
nice little script mate....

THis would make an excellent include for a ipn script im writing....

rep +



Thanks, i'm using it to record money i've made/spent at NP.

http://mikor.clearlyhosted.org/dac/graph.png

TwistMyArm 10-17-2006 12:27 PM

Not to take anything away from you Mikor, but for those who need something a little stronger and don't know about it, there's also the dual-licenced JPGraph library which does all sorts of graphs pretty nicely.

Barrucadu 10-17-2006 12:28 PM

Originally Posted by TwistMyArm
Not to take anything away from you Mikor, but for those who need something a little stronger and don't know about it, there's also the dual-licenced JPGraph library which does all sorts of graphs pretty nicely.



There is? Damn, i've wasted a few hours, lol

TwistMyArm 10-17-2006 12:43 PM

So long as you learnt something along the way, you didn't waste any time!

JPGraph is really good: admittedly, it doesn't build the graph straight in to the HTML as yours seems to, but it does do awesome graphs into various file formats. Trust me, it's worth the time to learn!


All times are GMT -7. The time now is 11:06 AM.
Site Sponsors
Advertise your business at NamePros

Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0