NameSilo

Graphs with PHP

Spaceship Spaceship
Watch

Barrucadu

Established Member
Impact
64
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:
//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.'     ';
     }elseif($point <= 99){
          echo $day['income'].'    ';
     }elseif($day['income'] <= 999){
          echo $day['income'].'   ';
     }
}
echo '</span>';
 
1
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
nice little script mate....

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

rep +
 
0
•••
templaterave said:
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.

graph.png
 
0
•••
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.
 
0
•••
TwistMyArm said:
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
 
0
•••
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!
 
0
•••

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back