for (var i = start; i <= end; i++) {
MultTbl += '<tr>';
MultTbl += '<th>' + i + '</th>';
for (var j = 0; j < last; j++) {
var val = (i * (start + j));
MultTbl += '<td class="' + getValueCss(val) + '">' + val + '</td>';
}
MultTbl += '</tr>';
}
function getValueCss(val, max) {
max = end * end;
var d = (max / 3);
if (val < d)
return 'high'
else if (val < (d * 2))
return 'middle'
else
return 'low'
}
3 Colors on Table
Page 1 of 12 Replies - 201 Views - Last Post: 03 December 2012 - 04:25 PM
#1
3 Colors on Table
Posted 03 December 2012 - 12:54 PM
I am very close to being done with this. I just a small error that I can't fix. I got the colours to work for 10 and 25, but when I enter in 100 and 110 it gives all red, I need about a third of the table each red, green, and yellow. The function getValueCss(val,max) is where I display my three colours on the table.
Replies To: 3 Colors on Table
#2
Re: 3 Colors on Table
Posted 03 December 2012 - 03:05 PM
I would suggest something like so:
Basically, you have to take into account your interval, instead of just the current value and maximum value.
NOTE - untested code.
Hopefully that makes sense.
function getValueCSS(val, start, end){ // where start and end are the same as the loop parameters
var max = (end - start) / 3;
if(val < start + max){ // val < start + ((end - start) / 3)
return "high"; // this should perhaps be low, since it is the lower third of the interval
}
if(val < start + (max * 2)){ // val < start + ((end - start) * 2 / 3)
return "middle"; // middle third
}
return "low"; // highest third
}
Basically, you have to take into account your interval, instead of just the current value and maximum value.
NOTE - untested code.
Hopefully that makes sense.
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote




|