Color Cells Containing Specific Ranges of Values

From Q
Jump to navigation Jump to search

This code obtains the p value from a table and colors any cells containing values of p less than 0.05.

 // Color yellow any cell that a p-value of less than 5%.
 // Get p-values array.
 var ps = table.get('p');
 // Get the cell colors array.
 var colors = table.cellColors;
 // Look at each cell...
 for (var row = 0; row < table.numberRows; row++)
 	for (var column = 0; column < table.numberColumns; column++) {
 		// Get the cell's p-value.
 		var p = ps[row][column];
 		// If the value is less than 5%, color this cell yellow.
 		if (p < 0.05)
 			colors[row][column] = 'yellow';
 	}
 // Store the modified cell colors.
 table.cellColors = colors;

See also