10-17-2006, 09:59 AM
· #1 Resident Linux Geek
Name: Michael Walker
Location: East Yorkshire, England
Join Date: Aug 2005
Posts: 2,408
NP$: 300.25 (
Donate )
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 . ' ' ;
}elseif( $point <= 99 ){
echo $day [ 'income' ]. ' ' ;
}elseif( $day [ 'income' ] <= 999 ){
echo $day [ 'income' ]. ' ' ;
}
}
echo '</span>' ;
10-17-2006, 10:24 AM
· #2 An American Soldier
Name: Ray
Location: Pennsylvania
Join Date: Jun 2005
Posts: 1,387
NP$: 37.00 (
Donate )
nice little script mate....
THis would make an excellent include for a ipn script im writing....
rep +
__________________
<--An American Soldier-->
TheyMix.com
10-17-2006, 12:05 PM
· #3 Resident Linux Geek
Name: Michael Walker
Location: East Yorkshire, England
Join Date: Aug 2005
Posts: 2,408
NP$: 300.25 (
Donate )
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
10-17-2006, 12:27 PM
· #4 NamePros Member
Join Date: May 2006
Posts: 155
NP$: 81.00 (
Donate )
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.
10-17-2006, 12:28 PM
· #5 Resident Linux Geek
Name: Michael Walker
Location: East Yorkshire, England
Join Date: Aug 2005
Posts: 2,408
NP$: 300.25 (
Donate )
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
10-17-2006, 12:43 PM
· #6 NamePros Member
Join Date: May 2006
Posts: 155
NP$: 81.00 (
Donate )
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!
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off