Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

[1726] A Horizontal Percentage Gauge

Last post 10-29-2004 7:39 AM by juliara. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 01-01-1999 12:00 AM

    [1726] A Horizontal Percentage Gauge

    This thread is for discussions of A Horizontal Percentage Gauge.

    • Post Points: 0
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 10-03-2003 7:39 AM In reply to

    • ferryb
    • Not Ranked
    • Joined on 10-03-2003
    • New Member
    • Points 5

    a php version

    <!doctype html public "-//W3C//DTD HTML 4.0 //EN">
    <html>
    <head>
       <title>horizontal gauge test</title>
    </head>
    <body>

    <?php

    class myGauge {

       // Color
       var $BgColor = "#FFFFFF", $FgColor = "#990000";
       // Dimensions.
       var $Width = 125, $Height = 10;
       // Values.
       var $MinVal = 0, $MaxVal = 100, $CurVal = 77;

       // Set values
       function setValues($fgc, $bgc, $wid, $hei, $min, $max, $cur) {
           $this->BgColor = $fgc;
           $this->FgColor = $bgc;
           $this->Width   = $wid;
           $this->Height  = $hei;
           $this->MinVal  = $min;
           $this->MaxVal  = $max;
           $this->CurVal  = $cur;
       }

       // Render this into HTML as a table.
       function display() {

           // Normalize the properties.
           if ($this->MinVal > $this->MaxVal) {
               $temp_val = $this->MinVal;
               $this->MinVal = $this->MaxVal;
               $this->MaxVal = $temp_val;
           }

           if ($this->CurVal < $this->MinVal) {
               $this->CurVal = $this->MinVal;
           }
           elseif ($this->CurVal > $this->MaxVal) {
               $this->CurVal = $this->MaxVal;
           }

           // Figure out the percentage that the CurVal is within MinVal and MaxVal.
           $percentage_val = ($this->CurVal - $this->MinVal) / ($this->MaxVal - $this->MinVal);

           // Compute the first and second widths.
           $fg_width = Round($this->Width * $percentage_val);
           $bg_width = $this->Width - $fg_width;

           $RenderHtml = "<table cellspacing=0 cellpadding=0 width=" . $this->Width . " height=" . $this->Height . "><tr>";
           if ($fg_width > 0) {
               $RenderHtml = $RenderHtml . "<td width=" . $fg_width . " height=" . $this->Height . " bgcolor=" . $this->FgColor .
                   "><img src=\"/images/shim.gif\"></td>";
           }
           if ($bg_width > 0) {
               $RenderHtml = $RenderHtml . "<td width=" . $bg_width . " height=" .
               $this->Height . " bgcolor=" . $this->BgColor . "><img src=\"/images/shim.gif\"></td>";
           }
           $RenderHtml = $RenderHtml . "</tr></table>";
           
           print $RenderHtml;
           
       }

    }

    // Main

    $oGauge = new myGauge();

    /*
    // Use method setValues to set datamembers, like:
    $fc = "#FFFFFF";
    $bc = "#990000";
    $wi = 125;
    $hi = 10;
    $mi = 0;
    $ma = 100;
    $cu = 87;
    $oGauge->setValues($fc, $bc, $wi, $hi, $mi, $ma, $cu);
    */

    ?>

    <!-- Display the gauge -->
    <table cellpadding=0 cellspacing=2>
       <tr>
           <td><?php $oGauge->display(); ?></td>
       </tr>
    </table>

    </body>
    </html>
    • Post Points: 0
  • 10-29-2004 7:39 AM In reply to

    • juliara
    • Not Ranked
    • Joined on 10-29-2004
    • New Member
    • Points 5

    printing percentage bar?

    Have you had any problems printing this bar?  It comes up transperent on a printed page.
    • Post Points: 0
Page 1 of 1 (3 items)