3 Replies - 1287 Views - Last Post: 04 December 2012 - 10:33 AM

#1 code098  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 25-October 12

Colors on table cells

Posted 29 November 2012 - 08:24 PM

How can I get it to where if I put any number the code should generate the table and set the class of each cell to indicate the relative size of the value. So about a third of the table should have 3 colors. Below is the code that worked for 10 and 25. About a third of the table should be each colour.

function getValueCss(val) {
if (val <= 231)
return 'high'
else if (234 <= val && val <= 360)
return 'middle'
else
return 'low'
}



How can I get it to where if I put any number the code should generate the table and set the class of each cell to indicate the relative size of the value. So about a third of the table should have 3 colors. Below is the code that worked for 10 and 25. About a third of the table should be each colour. I created the table already I just can't figure out how to get the colors on the table. The code below only shows the color green because my class high in style.css is set to green.

function getValueCss(val) {
if (val <= 231)
return 'high'
else if (234 <= val && val <= 360)
return 'middle'
else
return 'low'
}

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Colors on table cells

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3485
  • View blog
  • Posts: 10,043
  • Joined: 08-June 10

Re: Colors on table cells

Posted 29 November 2012 - 11:57 PM

View Postcode098, on 30 November 2012 - 04:24 AM, said:

I created the table already I just can't figure out how to get the colors on the table.

how do you create the table (as this influences the ways you can assign the classes).


PS. in the else if() condition you donít need the first part. (unless you want to have that potential miscoloured gap between 231 and 234). the lower bound is already covered by the first if().
Was This Post Helpful? 1
  • +
  • -

#3 code098  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 25-October 12

Re: Colors on table cells

Posted 03 December 2012 - 12:03 PM

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.

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 - 1;
					var d = Math.floor(max / 3);
					if (val < d)
						return 'high'
					else if (val < (d * 2))
						return 'middle'
					else
						return 'low'
				}



Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3485
  • View blog
  • Posts: 10,043
  • Joined: 08-June 10

Re: Colors on table cells

Posted 04 December 2012 - 10:33 AM

from the table code itself it should almost work (you donít pass in the max value), but the getValueCss() function is buggy.

there is no variable/parameter end, so you end up with max = NaN (NaN - Not a Number), which screws the whole calculation.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1