Skip to content
Reference > Methods

gradient(value,value1,color1,value2,color2,moreNumbersAndColors)

Definition

String gradient(Number value, Number value1, String color1, Number value2, String color2, Object ... moreNumbersAndColors)

Description

Requires a value and a list of number+color pairs. It will return a color that properly represents the supplied value. For example, given the pairs 0=black and 2=white,1 will return grey, any value <= 0 will return black and any value >=2 will return white. Colors must be in standard html notation (#RRGGBB), ex: #AABB88. At least 2 number+colorpairs are required but additional pairs can be provided in the var args parameter

Parameter Definition

Name Type Description
value Number Value to return color for
value1 Number Value associated with color1
color1 String color associated with value1(must be in #RRGGBB format)
value2 Number Value associated with color2
color2 String color associated with value2(must be in #RRGGBB format)
moreNumbersAndColors Object... Additional value/number pairs, must be even number of elements, where even elements are a number and odd elements are a color

Examples

1
2
3
4
String r1 = gradient(0.5D,0,"#000000",1,"#FFFFFF"); // r1 == #7f7f7f
String r2 = gradient(1.5D,0,"#000000",1,"#FFFFFF",2,"#FF0000"); // r2 == #ff8080
String r3 = gradient(3,0,"#000000",1,"#FFFFFF",2,"#FF0000"); // r3 == #ff0000
String r4 = gradient(-1,0,"#000000",1,"#FFFFFF",2,"#FF0000"); // r4 == #000000