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

Quickie bar graph widget for use in Apex Reports...

dmann — Fri, 05/22/2009 - 13:34

I'm trying not to scare my users off with endless rows and columns of numbers. I have an app that analyzes memory usage and swap space usage of some of our servers. Instead of throwing all kinds of computer sciency '65535' and '32767' numbers at my user I decided to create a small function to return a bar graph widget. Here is an example of the graph in use: Here is a function that will return the HTML for the widget:
CREATE OR REPLACE FUNCTION GetGraph (p_value IN NUMBER, p_total IN NUMBER) 
RETURN VARCHAR2
IS 
  my_retval VARCHAR2(1024);
  my_usedpercentage NUMBER := 0;
BEGIN

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

    my_retval := '<table width=104 border=0 style=single bgcolor=#AAAAAA><tr><td><table width=';
    my_retval := my_retval || my_usedpercentage;
    my_retval := my_retval || ' height=15 bgcolor=#0000FF><tr><td></td></tr></table></td></tr></table>';

    RETURN my_retval;

END;
/
The math is done inside the function to arrive at the percentage so you can feed it raw numbers and let the function do the heavy lifting. For example, in the first row and column above, (38285.5 free / 65536 total) *100 = 58% free. So 58 pixel width is shown as 'free', 42 pixel width is shown as 'used'. To use it you just have to work the GetGraph function into the SELECT list of your report query. For my purposes it goes a little something like this:
SELECT SERVER_NAME,
       GetGraph(FREEMEM,TOTALMEM) as "Memory Used",
       TOTALMEM as "Total Memory Mb",
       FREEMEM as "Free Memory mb",
       GetGraph(FREESWAP,TOTALSWAP) as "Swap Used",
       TOTALSWAP as "Swap Total mb",
       FREESWAP as "Swap Free mb"
FROM SERVER_DETAIL
ORDER BY SERVER_NAME
  • 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.
5 + 11 =
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.