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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bargraph class - need advice

Status
Not open for further replies.

DaveC426913

Programmer
Jul 28, 2003
274
CA
I want to make a bar graah class, but I'm not sure how to make it OO and efficient.

I will supply

1] a multi-dimensioned array of data (col1(value, label, colour),col2(value, label, colour),etc)

3] Some application-wide parameters (font, etc.)

4] Some table-level style params (border:Y/N, vertical vs. horizontal orientation, xyoffset)

5] Some data-display-specific params (columnwidth, columngutter, horizontal-lines-every-number-of-units, etc.)



Below is a snippet of what I've got so far. It seems pretty inefficient in terms of what fucntinos and varaibles are available and how easy it is to set them or call them. I could use some advice.

How can I break out the various functions? IS there more than one function? i.e. this works:
function DrawGraph(1 brazillion parameters){ ... }
Of course, that's very awkward, not to mention the fact that it doesan't support default params.

Any advice?



The call:

$g = new BarGraph($colarray);
$g->Show(225,230);


The class:

class BarGraph{

function BarGraph($colarray){
}

function Show($height,$width,$orientation=0,$border=1,$orientation=0,$colwidth=20,$colgap=1){
global $colarray;
if (orientation==0){
//vertical bars

//constants
$innerboxoffset=25;
$xinitialoffset=5;
?>
<style>
.xlbl{ ... }
.ylbl{ ... }
.bar{ ... }
</style>

<!-- outer border -->
<div style="position: absolute; left: 100px; height: <?=$height?>px; width: <?=$width?>px; border: <?
if ($border=1){ echo " 1px solid gray;"; }
else{ echo " none;"; }
?> overflow: hidden;">

<!-- inner border -->
<div style="position: absolute; left: <?=$innerboxoffset?>px; top:5px; bottom: 15px; height: 202px; width:200px; border: 1px solid gray; overflow: hidden;">

<!-- bars -->
<? for ($col=1;$col<=sizeOf($colarray);$col++){?>
<div class="bar" style="left: <?=(($col-1)*($colwidth+$colgap)+$xinitialoffset)?>px; width: <?=$colwidth?>px; background-color: <?=$colarray[$col][colour]?>; top:<?=(200-$colarray[$col][value])?>px;"><?=$colarray[$col][value]?></div>
<?}?>

etc. etc.
 
While I might entertain canned solutions, I do need the practice in coding.

I want it to be very lean. The reason I'm doing it in the first place is because my current methods of retrieving data from my db and displaying it are actually timing out - they're pretty inefficient.

Also, I don't need them as fancy-schmancy as jpgraph seems to be. Simple is better.
 
Even if the class is not what you want, you might be able to look at the class and steal be inspired by their ideas. I mean, you are asking for advice on how to design a class that creates a bar graph -- perhaps their source code will be a good source of advice.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top