Table colors according to values


I have a table that is bound to a memory dataset tag, the first two columns have the values of the memory tag, which are default values (Diameter and Length), and in the next two columns through a script, I’m reading the values I’m actually getting from a PLC and comparing them, if they are ok they just display the values, if they’re out of spec then it displays “OUT OF SPEC!!!” but I want to take it a bit further and change the background and text colors, is there a way to do it?

here’s an image of what I have

And here’s the script I’m using:

rows = value.getRowCount()
tool = {}
new_data = {}
tool_dia = {}
dia_default = {}
len_default = {}
tool_len = {}
len_default = {}
new_data_len = {}
check_dia = {}
check_len = {}
new_data[0] = value
i = 0
j = 0

for row in range(rows):
	tool[i] = value.getValueAt(row, 'Tool #')
	tool_dia[i] = + tool[i] + ' Data/' + tool[i] + '_Diameter')
	dia_default[i] = value.getValueAt(row, 'Diameter')
	new_data[row+1] = system.dataset.setValue(new_data[i], row, 'Loaded Diameter', tool_dia[i].value)
	check_dia[i] = new_data[i+1].getValueAt(i, 'Loaded Diameter')
	if check_dia[i] != dia_default[i]:
		check_dia[i] = 'OUT OF DIMENSION!!!'
		new_data[row+1] = system.dataset.setValue(new_data[i], row, 'Loaded Diameter', str(check_dia[i]))
	#new_data_len[row+1] = system.dataset.setValue(new_data[row+1], row, 'Loaded Length', tool_len.value)
	i = i+1

new_data_len[j] = new_data[i]

for row in range(rows):
	tool[j] = value.getValueAt(row, 'Tool #')
	tool_len[j] = + tool[j] + ' Data/' + tool[j] + '_Length')
	len_default[j] = value.getValueAt(row, 'Length')
	new_data_len[row+1] = system.dataset.setValue(new_data_len[row], row, 'Loaded Length', tool_len[j].value)
	check_len[j] = new_data_len[j+1].getValueAt(j, 'Loaded Length')
	if check_len[j] != len_default[j]:
		check_len[j] = 'OUT OF DIMENSION!!!'
		new_data_len[row+1] = system.dataset.setValue(new_data_len[j], row, 'Loaded Length', str(check_len[j]))
	j = j+1
return new_data_len[j]

This is indeed possible. I am using a power table for this and assuming you are using Vision.

You need to attach the following code to your power table ‘Configure Cell’ Extension Function.

	if colName == 'value':
		min =, 'min')
		max =, 'max')
		val =, 'value')
		if val >= min and val <= max:
			return {'background': 'WHITE', 'foreground':'BLACK'}
		elif val < min:
			return {'background': 'GREEN', 'foreground':'WHITE'}
			return {'background': 'RED', 'foreground':'WHITE'}

You can change the background color or the foreground color to whatever you want. Make sure to specify the column name.

You can also add in or change the text that is displayed in this method as well by adding the key ‘text’ to the returned dictionary.

	if colName == 'value':
		min =, 'min')
		max =, 'max')
		val =, 'value')
		if val >= min and val <= max:
			return {'background': 'WHITE', 'foreground':'BLACK', 'text':'Underperforming'}
		elif val < min:
			return {'background': 'GREEN', 'foreground':'WHITE', 'text':'GOOD'}
			return {'background': 'RED', 'foreground':'WHITE', 'text':'Overperforming'}

I attached an example window that does this. (7.8 KB)

Thank you very much! I’m actually using Perspective, but I’ll give it a try!