Christoph's 2 Cents

A Backup for My Brain!

Oracle Application Express (Apex)Oracle DevelopementPL/SQL

Color Spectrum in APEX report

I recently had the need to display a color spectrum, depending on a column value, in a report. The colors had to go from red (column value zero) to green (column value 100).

color_spectrum

To achieve this I added a formula to my query that would generate an RGB value based on the column value. I then used this value to render a circle of that color, with the column value inside of it.

Here  is the sample query for the report. The report has two columns:
VALUE: The value I wish to display.
VALUE_COLOR: The generated RGB color that gets used in the VALUE’s HTML Expression.

[sourcecode language=”sql”]
select level as value
,’rgb(‘||round((255 * (100 – level)/100),0)
||’,’|| round((255 * level)/100,0) ||’,0’||’)’
as value_color
from dual
connect by level <= 100
order by 1
[/sourcecode]

I used some custom HTML in the Value column’s HTML Expression to render a Font Awesome circle in the color of the generated RGB value, with the column value inside.

column

That’s it. Have fun with it.