ba6.us - Dave's Database Related Stuff

  • home
  • blog
  • notebooks
  • projects
  • recent
  • about
  • manifesto
  • !
Home › Blogs › dmann's blog

Tag Cloud

apex Application Express Auditing data dbi development export funnies HTML Java linux monitoring oem oracle performance perl rman scripting sql SQL Developer sqlplus tuning unix windows
more tags

Search

RSS Feed

Blog Posts :

Navigation

  • Feed aggregator

User login

  • Request new password

Can't leave well enough alone...

dmann — Tue, 05/26/2009 - 12:55

Here is some code to update the previous widget to show data in a green/yellow/red bar graph like an audio meter: The code is here:
CREATE OR REPLACE FUNCTION GetGraph (p_value IN NUMBER, p_total IN NUMBER DEFAULT 100) 
RETURN VARCHAR2
IS 

  -- David Mann
  -- 05/26/2009
  -- Create HTML bar graph widget for use in Application Express reports. 
  -- Has thresholds for yellow and red. 
  -- Parameters: p_value - Top of ratio fraction or percentage as whole number (0-100)
  --             p_total - Bottom of ratio fraction or default to 100

  my_retval VARCHAR2(1024);
  my_usedpercentage NUMBER := 0;
  topgreen  NUMBER := 80; -- Top of green region
  topyellow NUMBER := 95; -- Top of yellow region
BEGIN

    if (p_total > p_value) then
        my_usedpercentage := 100 - ROUND( (p_value / p_total) * 100 );
    end if;

    my_retval := my_retval||'<table width=120 border=0 style=single bgcolor=#AAAAAA><tr><td>';
    my_retval := my_retval||'<table><tr>';
    
    
    if (my_usedpercentage >= 0 and my_usedpercentage <= topgreen) then 
      my_retval := my_retval||'<td width='||my_usedpercentage||' height=15 border=0 bgcolor=#00FF00></td>';
    end if;
 
    if (my_usedpercentage > topgreen and my_usedpercentage <= topyellow) then 
      my_retval := my_retval||'<td width='||topgreen||' height=15 border=0 bgcolor=#00FF00></td>';
      my_retval := my_retval||'<td width='||(my_usedpercentage-topgreen)||
          ' height=15 border=0 bgcolor=yellow></td>';
    end if;
 
    if (my_usedpercentage > topyellow) then 
      my_retval := my_retval||'<td width='||topgreen||' height=15 border=0 bgcolor=#00FF00></td>';
      my_retval := my_retval||'<td width='||(topyellow-topgreen)||
          ' height=15 border=0 bgcolor=yellow></td>';
      my_retval := my_retval||'<td width='||(my_usedpercentage-topyellow)||
          ' height=15 border=0 bgcolor=red></td>';
    end if;

  my_retval := my_retval||'</tr></table>';
    my_retval := my_retval||'</td></tr></table>';

    RETURN my_retval;

END;
/
-Dave
  • apex
  • Application Express
  • Graph
  • HTML
  • dmann's blog

Post new comment

The content of this field is kept private and will not be shown publicly.
Input format
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
4 + 3 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.


Cornify
  • home
  • blog
  • notebooks
  • projects
  • recent
  • about
  • manifesto
  • !

Content Copyright 2006-2010. Links are copyright of respective owners.