:: Forum >>

Conditional Font Color (RAG-Concept)

Hi All,

I'm trying to interpret the percental utilization in a column as basis for the font color of the same column. The result should be a dynamic color spectrum from green (0%) to red (100%). The arithmetic calculation of the color HEX-Code is no big deal, but I'm lacking the proper code to assign it as font color to the last column in the table.

In the current version of my source code, I've writte the HEX color to the 2nd column for debugging purposes:

<title>ActiveWidgets Examples</title>
<style>body {font: 1ppx Tahoma}</style>
<script src="testaw/aw.js"></script>
<link href="testaw/aw.css" rel="stylesheet"></link>
#myGrid {height: 200px; width: 500px;}
#myGrid .aw-row-selector {text-align: center}
#myGrid .aw-column-0 {text-align: left;}
#myGrid .aw-column-1 {text-align: left;}
#myGrid .aw-column-2 {text-align: right;}
#myGrid .aw-column-3 {text-align: right;}
#myGrid .aw-column-4 {text-align: right;}
#myGrid .aw-grid-row {border-bottom: 1px solid threedlightshadow;}
#myGrid .aw-grid-cell {border-right: 1px solid threedlightshadow;}
var myCells = [

var obj = new AW.UI.Grid;
var columns = ["Date", "Time", "Available", "In-Use", "Utilization"];
var string = new AW.Formats.String;
var int = new AW.Formats.Number;
var float = new AW.Formats.Number;
float.setTextFormat("###.## %");
obj.setCellFormat([string, string, int, int, float]);
function sum(column,row){ return this.getCellValue(3, row) / this.getCellValue(2, row) * 100; }
obj.setCellData(sum, 4);

function hexco(column,row){ util = parseInt ( this.getCellValue(3, row) / this.getCellValue(2, row) * 255 ) ; utilneg = 255 - util ; red = utilneg.toString(16) ; green = util.toString(16) ; return "#" + red + green + "00" ; }
obj.getCellTemplate(4).setStyle("color","blue") ;



Has anybody got an idea what's necessary to solve this problem? Thank you for any kind of reply
Monday, May 14, 2007
Hi all,

a further forum search revealed a new approach to this problem. Someone suggested to perform the color assignment in a for-loop, and voila, it works:

function myColor(available,inuse){util=parseInt(inuse/available*255);utilneg=255-util;red=util.toString(16);if(util<=16)red="0"+red;green=utilneg.toString(16);if(utilneg<=16)green="0"+green;return "#"+red+green+"00";}

Maybe this thread saves other users from tearing their hair ;-).
Monday, May 14, 2007
Modifying each cell template in a loop might be quite slow. Instead you could define a new calculated cell property ('color') and link the cell template style to it, see the example here -

Alex (ActiveWidgets)
Monday, May 14, 2007

This topic is archived.

Back to support forum

Forum search