Skip to Main Content
Ted Struik - Oracle
Search For
Home
Home
Ted Struik - Oracle
Search
Site Map
Statistics
Page Errors
Apex
Apex
General
Autocomplete
Conditions
Errors
Items used in PL/SQL
Validations
Dynamic Actions
Logs
Version
App-wide Items
Error Handling
Apex Views
Apex Upgrade 4.2 to 5.1
Apex Upgrade 20.2 to 23.1
Database Dependencies
Show Source Code
URLs
Authorization
Modal Dialogs
Apex Office Print (AOP)
Apex-Sert
Warn on Unsaved Changes
Form Regions
Reports
Checkboxes
Download
Errors
Nowrap Columns
Substitution Strings
Use IR results in pl/sql
Clickable Row
Row Highlight
Translate Filters etc.
Bar Charts
Column Usage
Reset Pagination
Hide IR Actions menu items
Get Classic Report query
Interactive Grid
ORA-20987
ERR-1002
Copying Text
IG Info
Multiple Row Select
Read Only Options
Search
Sort and Search
Images & Fonts
Standard Icons & Fonts
WebDav
Font Awesome
Icons/image popup LOV
Lists
Hierarchy
LOVs
Definition Bug
Set 1-item LOV to Disabled
With Clause Errors
Modal LOV Plugin
HTML / CSS / JavaScript
Vertical Align
Legend CSS
Geolocation
Apex.confirm
Pie Charts
Codemirror
Theme Roller
Catching Key Strokes
Browser Cache
Locale
RequireJS
Collapsible Regions
Find JavaScript
Import / Export
Dynamic Translations
Translated Pages
APEXExport (java)
apex_export (pl/sql)
Component Settings
Charts
Translate Charts
[Reports] Bar Charts
Shuttles
Shuttle Sorting
Disable Shuttle Items
Menus
Accordion-Like
Scroll bug
Authorization
Session State
About Session State
Rollback & Commit
Performance of v()
Apex Clone Session
Request
Session State in Views
Collections
ORA-20101 & ORA-20104
ORA-00001
Max Row Count
(PL)SQL
(PL)SQL
External Tables
SQL Plus
Conditions
Long
ORDImage
Date & Timestamp
CGI environment
Sys_context
Rounding percentages
Apex_string.split in SQL
Dbms_metadata
Instr
Regular Expressions
Rollback to Savepoint
Use table aliases
(Pipelined) Bulk Collect
JSON
Source Code Search (PL/SQL)
Source Code Search (SQL)
Format Models
Pipelined Table Functions
Hint no_unnest
Listagg
DBA
DBA
Backup & Restore
Users
Export & Import
DBMS Jobs
Tablespaces
Table Size
Flush cache
Access Control List (ACL)
Locks
Java
Constraints
Object Dependencies
Package Dependencies 1
Package Dependencies 2
Grants
SQL History
Startup Errors
ORDS
Miscellaneous
Miscellaneous
Holidays
E-mail
NLExtract
Windows
VPN
VMware
Links
Google
Visualization Orgchart
Hide Search Results
Reverse Proxy
To-do List
Cytoscape
Graphics
Upscaling
Amazon Prices
Domoticz
DDoS
Hobbies
Hobbies
Motorcycles
'95 Kawasaki ZZR 600
'94 Kawasaki ZZR 1100
'91 Honda CBR 600 F2
'95 Kawasaki ZZR 1100
'99 Honda CBR 1100 XX
'00 Honda CBR 1100 XX
'02 Kawasaki ZX-12R (NL)
'05 Ducati 999 (NL)
'08 Honda Fireblade
'07 Suzuki Bandit 1250A
'18 Suzuki GSX-S 1000 F
MotoGP
Garfield
Lyrics
Skydive
Woodworking
Pantorouter
16 inch Bandsaw
Introduction
Frame
Wheels
Wheel mounts
Blade guides
Trunions and table
Enclosure
Alignment and more
Box Joint Jig
Foldable Sawhorses
Strip Sander XL
Photography
Sony RX10 IV
Yes Minister
WinAmp
IR
Go
Actions
Year
N 10
N 10 P Fmt
N 20
N 20 P Fmt
N 30
N 30 P Fmt
N
N P Fmt
1980
0
1
0
0%
1
0
100
0
1981
2
2
6
60%
10
20
20
60
1982
1
1
0
0%
2
50
50
0
1983
0
1
0
0%
1
0
100
0
Column Actions
Search
Info
An extension of the standard Apex Reports column formatting functionality "Graphical formatting for percentages, whole numbers between 0 and 100" (i.e. percentage bars). More info by Martin D'Souza on the standard Apex functionality:
http://www.talkapex.com/2009/06/displaying-percentage-bar-in-apex/
The package used here adds the option to show more than 1 percentage per bar in a column, and also adds options for custom CSS formatting.
At the suggestion of Nguyen Thanh Tu, I have added the option to add a text label inside the bar.
In the example above, the columns are formatted as follows:
N 10 P : Standard number formatting for percentage bars (PCT_GRAPH:cccccc:ff0000:150)
N 20 P Fmt : Uses the new function to mimick the standard formatting
N 30 P Fmt : Uses the new function to showcase some fancy (and rather hideous, in this case...) formatting, and shows the text label option
N P Fmt: Uses the new function to combine the other 3 peecentages into 1 bar, and shows the text label option per percentage
Note:
This works fine for Apex version 4.2 through 19.2. Older/newer versions may use slightly different classes and css to format the divs. Study the html produced by Apex and change the package accordingly.
Code
Page
Identification
Page ID
1069
Name
Apex - Reports - Bar Charts
Region
Identification
Sequence
10
Title
IR
Type
Interactive Report
Source
Source Type
DYNAMIC_QUERY
Region Source
with a as ( select to_char(e.hiredate, 'YYYY') as year , count(*) as n , count(case when e.deptno = 10 then 1 else null end) as n_10 , count(case when e.deptno = 20 then 1 else null end) as n_20 , count(case when e.deptno = 30 then 1 else null end) as n_30 from emp e group by to_char(e.hiredate, 'YYYY') ) , b as ( select a.* , 100 * a.n / a.n as n_p , 100 * a.n_10 / a.n as n_10_p , 100 * a.n_20 / a.n as n_20_p , 100 * a.n_30 / a.n as n_30_p from a ) select b.* , ted_p1069.div(p_width => '150px', p01_perc => b.n_10_p, p01_color_f => 'coral') as n_10_p_fmt , ted_p1069.div(p_width => '150px', p01_perc => b.n_20_p, p01_color_f => 'lawngreen') as n_20_p_fmt , ted_p1069.div ( p_width => '150px' , p_height => '25px' , p_style_b => 'background:repeating-radial-gradient(white, #ccc 10%, yellow 15%);' , p01_perc => b.n_30_p , p01_color_f => null , p01_style => 'background:linear-gradient(to top right, cyan, blue);' , p01_text => trim(b.n_30_p) || '%' , p01_title => 'Nice blue bar on rather hideous background' ) as n_30_p_fmt , ted_p1069.div ( p_width => '150px' , p01_perc => b.n_10_p , p01_color_f => 'coral' , p01_text => trim(b.n_10_p) , p02_perc => b.n_20_p , p02_color_f => 'lawngreen' , p02_text => trim(b.n_20_p) , p03_perc => b.n_30_p , p03_color_f => 'cyan' , p03_text => trim(b.n_30_p) ) as n_p_fmt from b order by b.year
Package
Package
Name
TED_P1069
Source
package ted_p1069 is c_style_apex_42 constant varchar2(1000) := 'border-top:1px solid #aaaaaa;border-left:1px solid #aaaaaa;border-bottom:1px solid #ffffff;border-right:1px solid #ffffff;'; -- To imitate the default bar style of Apex 4.2 (and earlier, probably) use this value for div.p_style function div ( p_width in varchar2 := '150px' -- width of the entire bar; note you are not limited to pixels here, percentages etc. will also work , p_height in varchar2 := '20px' -- height of the entire bar; note you are not limited to pixels here, percentages etc. will also work , p_style in varchar2 := null -- additional style settings for the entire bar (remember to close it properly with ;) - to imitate Apex 4.2, use the value of constant c_style_apex_42 , p_color_b in varchar2 := '#CCCCCC' -- background color (see notes below) , p_style_b in varchar2 := null -- additional style settings for the background of the entire bar (remember to close it properly with ;) , p01_perc in number := 0 -- width (in percentage) of the (1st) bar; note that this is a number, not a varchar2 like p_width , p01_color_f in varchar2 := '#777777' -- foreground color of the (1st) bar (see notes below) , p01_style in varchar2 := null -- additional style settings for this part of the (1st) bar (remember to close it properly with a ;) , p01_text in varchar2 := null -- text to show on this part of the (1st) bar , p01_title in varchar2 := null -- title to show when hovering over this part of the (1st) bar , p02_perc in number := null , p02_color_f in varchar2 := null , p02_style in varchar2 := null , p02_text in varchar2 := null , p02_title in varchar2 := null , p03_perc in number := null , p03_color_f in varchar2 := null , p03_style in varchar2 := null , p03_text in varchar2 := null , p03_title in varchar2 := null ) return varchar2 ; end ted_p1069;
Package Body
Package Body
Name
TED_P1069
Source
package body ted_p1069 is /* Example original formatting generated by Apex 4.2: <div style="width:250px;height:14px;background:#CCCCCC;border-top:1px solid #aaaaaa;border-left:1px solid #aaaaaa;border-bottom:1px solid #ffffff;border-right:1px solid #ffffff;"> <img src="/i/1px_trans.gif" width="168" alt="168" height="14" border="0" style="background:#15BCF3;"> </div> */ /* Example original formatting generated by Apex 5.0: <div class="a-Report-percentChart" style="background-color:#cccccc;width:150px;"> <div class="a-Report-percentChart-fill" style="width:0%; background-color:#ff0000;"></div> <span class="u-VisuallyHidden">0%</span> </div> */ function div_f ( p_height in varchar2 , p_perc in number , p_color_f in varchar2 , p_style in varchar2 , p_text in varchar2 , p_title in varchar2 ) return varchar2 is v_result varchar2(4000); begin if p_perc is not null then v_result := '<div' || ' style="' || 'display: inline-block;' || ' width: ' || trim(round(p_perc)) || '%;' -- round used here to prevent decimal errors (dot vs comma) || ( case when p_height is not null then ' height: ' || trim(p_height) || ';' else '' end ) || ( case when p_color_f is not null then ' background-color: ' || p_color_f || ';' else '' end ) || ( case when p_style is not null then ' ' || p_style else '' end ) || '"' || ( case when p_title is not null then ' title="' || p_title || '"' else '' end ) || '>' || ( case when p_text is not null then '<div style="vertical-align: middle; padding-left: 3px; height: ' || trim(p_height) || '; display: table-cell; font-weight: bold;">' || p_text || '</div>' else '' end ) || '</div>' ; end if; return v_result; end div_f; function div ( p_width in varchar2 := '150px' -- width of the entire bar; note you are not limited to pixels here, percentages etc. will also work , p_height in varchar2 := '20px' -- height of the entire bar; note you are not limited to pixels here, percentages etc. will also work , p_style in varchar2 := null -- additional style settings for the entire bar (remember to close it properly with ;) - to imitate Apex 4.2, use the value of constant c_style_apex_42 , p_color_b in varchar2 := '#CCCCCC' -- background color (see notes below) , p_style_b in varchar2 := null -- additional style settings for the background of the entire bar (remember to close it properly with ;) , p01_perc in number := 0 -- width (in percentage) of the (1st) bar; note that this is a number, not a varchar2 like p_width , p01_color_f in varchar2 := '#777777' -- foreground color of the (1st) bar (see notes below) , p01_style in varchar2 := null -- additional style settings for this part of the (1st) bar (remember to close it properly with a ;) , p01_text in varchar2 := null -- text to show on this part of the (1st) bar , p01_title in varchar2 := null -- title to show when hovering over this part of the (1st) bar , p02_perc in number := null , p02_color_f in varchar2 := null , p02_style in varchar2 := null , p02_text in varchar2 := null , p02_title in varchar2 := null , p03_perc in number := null , p03_color_f in varchar2 := null , p03_style in varchar2 := null , p03_text in varchar2 := null , p03_title in varchar2 := null ) return varchar2 is -- Notes: -- Since all colors are pure CSS, you are not limited to the "#cccccc" hex notation here, all CSS variations (like 'blue' etc.) work as well. -- Likewise, widths and heights are CSS, so instead of pixels you can use percentages etc. -- To imitate the default bar style of Apex 4.2 (and earlier, probably) use the value of constant c_style_apex_42 as the value for p_style. v_result varchar2(4000); v_apex_version_1 pls_integer; v_apex_version_2 pls_integer; begin -- determine the Apex (sub)versions select to_number( substr(version_no, 1 , i1 ) ) , to_number( substr(version_no, i1+2, i2-i1-1) ) into v_apex_version_1 , v_apex_version_2 from ( select version_no , instr(version_no, '.', 1, 1)-1 as i1 , instr(version_no, '.', 1, 2)-1 as i2 from apex_release ) a ; -- build the div v_result := '<div' || ( case when v_apex_version_1 >= 5 then ' class="a-Report-percentChart"' else '' end ) || ' style="' || ' width:' || trim(p_width) || ';' || ( case when p_height is not null then ' height:' || trim(p_height) || ';' else '' end ) || ( case when p_style is not null then ' ' || p_style else '' end ) || '">' || '<div' || ( case when v_apex_version_1 >= 5 then ' class="a-Report-percentChart-fill"' else '' end ) || ' style="' || ( case when p_color_b is not null then 'background-color:' || p_color_b || ';' else '' end ) || ( case when p_height is not null then ' height:' || trim(p_height) || ';' else '' end ) || ( case when p_style_b is not null then ' ' || p_style_b else '' end ) || '">' || div_f( p_height => p_height, p_perc => p01_perc, p_color_f => p01_color_f, p_style => p01_style, p_text => p01_text, p_title => p01_title ) || div_f( p_height => p_height, p_perc => p02_perc, p_color_f => p02_color_f, p_style => p02_style, p_text => p02_text, p_title => p02_title ) || div_f( p_height => p_height, p_perc => p03_perc, p_color_f => p03_color_f, p_style => p03_style, p_text => p03_text, p_title => p03_title ) || '</div>' || '</div>' ; return v_result; end div; end ted_p1069;