#native_company# #native_desc#
#native_cta#

HTML_Graphs Page 3

By Tim Perdue
on July 30, 2000

That function is quite simple. Hand it a result set, it checks for the length,
then turns that result set into a set of arrays to pass into my other general function,
GraphIt(). GraphIt() can be called directly if you already have an array, or you
need to do some custom stuff with it that cannot be done with straight SQL.
Notice that GraphIt() will determine scale for you. It iterates through the values[] array
and finds the biggest value. It also builds an appropriate array of colors for the bars
on the graph.

<?php

Function GraphIt($names,$values,$title) {

    $counter=count($names);

    /*

        Can choose any color you wish

    */

    
for ($i 0$i $counter$i++) {

        
$bars[$i]="#DEDEEE";

    }

    $counter=count($values);

    /*

        Figure the max_value passed in, so scale can be determined

    */

    $max_value=0;

    for ($i 0$i $counter$i++) {

        if (
$values[$i] > $max_value) {

            
$max_value=$values[$i];

        }

    }

    if ($max_value 1) {

        
$max_value=1;

    }

    /*

        I want my graphs all to be 800 pixels wide, so that is my divisor

    */

    $scale = (int) (800/$max_value);

    /*

        I create a wrapper table around the graph that holds the title

    */

    echo "<TABLE BGCOLOR="NAVY" CELLSPACING=2 CELLPADDING=3>";

    echo 
"<TR><TD BGCOLOR="NAVY"><FONT COLOR=WHITE><B>$title</TD></TR><TR><TD>";

    /*

        Create an associatve array to pass in. I leave most of it blank

    */

    $vals =  array(

    
"vlabel"=>"",

    
"hlabel"=>"",

    
"type"=>"",

    
"cellpadding"=>"",

    
"cellspacing"=>"",

    
"border"=>"",

    
"width"=>"",

    
"background"=>"",

    
"vfcolor"=>"",

    
"hfcolor"=>"",

    
"vbgcolor"=>"",

    
"hbgcolor"=>"",

    
"vfstyle"=>"",

    
"hfstyle"=>"",

    
"noshowvals"=>"",

    
"scale"=>"$scale",

    
"namebgcolor"=>"",

    
"valuebgcolor"=>"",

    
"namefcolor"=>"",

    
"valuefcolor"=>"",

    
"namefstyle"=>"",

    
"valuefstyle"=>"",

    
"doublefcolor"=>"");

    /*

        This is the actual call to the HTML_Graphs class

    */

    html_graph($names,$values,$bars,$vals);

    echo "</TD></TR></TABLE>";

}

?>

So those two functions really do the heavy lifting for you. Determing scale was always a headache until
I built the wrapper classes, and sometimes the graph would be so large it would go off the page.