Change the table cell color based on value

Hi,

i am using normal table not power table


I have data in the table
i want to show red color for the value greater than 50 in all cells

how to do that for normal table?

I would use a power table if possible, but there is an extension function getBackgroundAt for a regular table where you could use this, YMMV

	if value > 50 and not isinstance(value,unicode):
		#print type(value)
		return system.gui.color(217,0,0)
	return defaultColor

You could also do this, for your specific table data

	if value > 50 and col != 0:
		return system.gui.color(217,0,0)
	return defaultColor

i am using tag history for 36 tags . normal table loading the data in few seconds but when i tested in power table its my client got hang and its doesn’t working fine

Works fine for me using the table’s test data :man_shrugging:

1 Like

yes tested. I just explained you why i didn’t used power table

Show your code in the Power Table’s extension functions. I’ll bet you are using a gateway callout in one of them.

no code i am using just tag history


36 tags i am using

Show your Power Table’s extension functions.


nothing i added

I thought you wasn’t using a power table?

yes i am not using… I tired in power tables its not worked properly…pturmel asked thats y i am showing

How many rows does the table have? Did you try this version?

if value > 50 and col != 0:
		return system.gui.color(217,0,0)
	return defaultColor

No issue your code is working fine in table.

3 Likes

Hi @dkhayes117
this is the code i am got from wincc reporting

= "#" & IIf(Int(Fields!H02.Value) < 1, "11ff",
IIf(Int(Fields!H02.Value) < 16, "ff" & Hex(17 * Int(Fields!H02.Value)),
IIf(Int(Fields!H02.Value) < 30, Hex(17 * (30-Int(Fields!H02.Value))) & "ff",
"ff11"
)
)
) & "00"

how to use this for power table in ignition. can you help me out what they return @PGriffith any way to pass background color like above mentioned script in configure cell?

That is an extremely ugly nested if that is generating a hex color code.

It looks like some test results are

'11ff00' # green  H02 < 1
'ff2200' # red H02 = 2
'ffff00' # yellow H02 = 15
'ddff00' # yellow H02 = 17
'11ff00' # green H02 = 29
'ff1100' # red H02 = 31

There maybe a better way to do this, but without reinventing the wheel, try this

H02 = int(self.data.getValueAt(row,"H02"))

if H02 < 1:
	color = "11ff00"
elif H02 < 16:
	color = "ff%s00" % hex(17 * H02)
elif H02 < 30:
	color = "%sff00" % hex(17 * (30-H02))
else:
	color = "ff1100"

return system.gui.color(color)	
1 Like

Thank u so much i will try and let u know

script is not working. Example image i have attached which i got from wincc report

You didn’t provide enough context in order for me to give you the correct answer. My script was only looking at H02 for every row, based on what you provided…

value = int(value)

if value < 1:
	color = "11ff00"
elif value < 16:
	color = "ff%s00" % hex(17 * value )
elif value < 30:
	color = "%sff00" % hex(17 * (30-value ))
else:
	color = "ff1100"

return system.gui.color(color)	
2 Likes

used your code but color is applying for few numbers only. Main thing is freezing the client i couldn’t able to access the window. Is there any way to run the script without freezing client?

The hex portion of the code is adding the 0x prefix to the number which throws off the color translation. There is most certainly a better way to fix that, but without researching it, this will fix it.

	value = int(value)
	
	if value < 1:
		color = "11ff00"
	elif value < 16:
		color = "ff%s00" % hex(17 * value).replace("0x","")
	elif value < 30:
		color = "%sff00" % hex(17 * (30-value)).replace("0x","")
	else:
		color = "ff1100"
	
	return system.gui.color(color)	
1 Like