Monday, June 1, 2009

Displaying Percentage Bar in APEX Reports

APEX can create "Percentage Bars" within a report. They're probably a lot of 3rd party tools you can use for fancy percentage bars, however if you want a basic display to the user here's a quick way to do it. Click here for a demo.



1- Create your report
In this report we're using the employees percentage of salary within their department


SELECT e.ename,
e.job,
d.dname,
e.sal,
ROUND (e.sal / SUM (e.sal) OVER (PARTITION BY e.deptno) * 100, 0) pct_dep_sal,
ROUND (e.sal / SUM (e.sal) OVER (PARTITION BY e.deptno) * 100, 0) bar
FROM emp e,
dept d
WHERE e.deptno = d.deptno


2- Add Percentage Bar for the "bar" column
- In the Reports Attributes section, click on the "Bar" column attributes
- Under Number/Date formatting enter the following: PCT_GRAPH:330099:CC0000:100

PCT_GRAPH:<Hex background color>:<Hex foreground color>:<Bar width in pixels>

8 comments:

  1. Cool! I like it.

    Where did you find information about this feature?

    ReplyDelete
  2. Hi Louis,

    I can't remember exactly where I found it but a long time ago I either asked about it on the forum or Scott Spendolini told me about it.

    I completely forgot about it until last week so I thought that I'd write about it since I couldn't find anything on the forums.

    ReplyDelete
  3. Maybe it was here: http://www.inside-oracle-apex.com/more-undocumented-new-features-in-oracle-apex-31/#high_2

    ;)

    But it definitely deserves repeating.

    Joel

    ReplyDelete
  4. Hi Joel,

    I don't like to copy other peoples post, so thanks for pointing that out. I didn't realize their was a pl/sql procedure for it as well.

    Thanks,

    Martin

    ReplyDelete
  5. I don't necessarily need it, but it's very neat and comes in handy! Already implemented it into my app!
    Thanks for posting it!

    ReplyDelete
  6. Hi,
    Thank you for the solution, its working fine in my report,but can I display the Percentage value in the graph itself or something like Tool Tip in the report column?

    ReplyDelete
    Replies
    1. If you're using APEX 5 check out the Sample Application. On the first page there's an excellent demo on how to do the tooltip in a report. I believe is a lugin region.

      Delete