Inspired by functions avaliable in other BI tools, this is some lightweight function snippets to put into SQL Server Reporting Services and other VB applications. All of the function in this script will return only Hex Color Codes as String, e.g. #F0ADFF
. The color function can then be easily fed into expressions.
More on colour model
Applying the code on SSRS, or if you want a more graphical guide
ColorMix ( Value, MaxValue, MinValue, MaxValueColor [, MinValueColor] )
A function that will interpolate intermediate colours between 2 specified colours according to value provided. Can be used to create gradient colour scales for heatmap.
Parameters | Type | Optional | Description |
---|---|---|---|
Value | Double | No | The value to be evaluated over MaxValue and MinValue, usually between MaxValue and MinValue. Values that overshoot the range will be truncated. |
MaxValue | Double | No | The value that correspond to MaxValueColor. Value larger than MaxValue will gives color that specified in MaxValueColor. The closer the value gets to the MaxValue supplied, the closer the color to MaxValueColor. |
MinValue | Double | No | The value that correspond to MinValueColor or white. Works pretty the same (or opposite) to MaxValue, and should be smaller than the MaxValue. |
MaxValueColor | String | No | The Hex Colour Code for the colour that correspond to MaxValue. Example #20ADFF . |
MinValueColor | String | Yes | The Hex Colour Code for the colour that correspond to MinValue. If no value is supplied, the MinValue will correspond to white #FFFFFF ). |
ColorMix2 ( Value, MaxValue, MinValue, MaxValueColor , MinValueColor [, MidValueColor] )
A function that will interpolate intermediate colours between 3 specified colours according to value provided. Can be used to create gradient colour scales with 2 sides for heatmaps or other plots (e.g. blue-white-red). It is just a two-sided version of the ColorMix()
function.
Parameters | Type | Optional | Description |
---|---|---|---|
Value | Double | No | The value to be evaluated over MaxValue and MinValue. Values that overshoot the range will be truncated. If value falls between MaxValue and the middle of MaxValue and MinValue, a ColorMix between Max and Mid Colour (default white) will be returned. |
MaxValue | Double | No | The value that correspond to MaxValueColor. Value larger than MaxValue will gives color that specified in MaxValueColor. The closer the value gets to the MaxValue supplied, the closer the color to MaxValueColor. |
MinValue | Double | No | The value that correspond to MinValueColor or white. Works pretty the same (or opposite) to MaxValue. |
MaxValueColor | String | No | The Hex Colour Code for the colour that correspond to MaxValue. Example #20ADFF . |
MinValueColor | String | No | The Hex Colour Code for the colour that correspond to MinValue. Example #AAD3FF . |
MidValueColor | String | Yes | The Hex Colour Code for the colour that correspond to MidValue. If no value is supplied, the MidValue will correspond to white #FFFFFF ). |
RGB ( red, blue, green)
Converts a RGB color code into Hex Colour Code that can be used by applications as expressions.
Parameters | Type | Optional | Description |
---|---|---|---|
red | Double | No | Between 0 and 255. Non integral value will be rounded off and values that overshoot will be truncated. Represents the numerical value for red. |
green | Double | No | Same as above (but green). |
blue | Double | No | Same as above (but blue). |
HSL ( hue, saturation, lightness)
Converts a HSL color code into Hex Colour Code that can be used by applications as expressions.
Parameters | Type | Optional | Description |
---|---|---|---|
hue | Double | No | Between 0 and 1. Represents the degree of hue. Expecting to be larger than or equal to 0 and smailler than 1. |
saturation | Double | No | Between 0 and 1. Saturation of the colour. Values taht overshoot will be truncated. |
lightness | Double | No | Between 0 and 1. Lightness of the colour. Values that overshoot will be truncated. |
HSV ( hue, saturation, value)
Converts a HSL color code into Hex Colour Code that can be used by applications as expressions.
Parameters | Type | Optional | Description |
---|---|---|---|
hue | Double | No | Between 0 and 1. Represents the degree of hue. Expecting to be larger than or equal to 0 and smailler than 1. |
saturation | Double | No | Between 0 and 1. Saturation of the colour. Values taht overshoot will be truncated. |
value | Double | No | Between 0 and 1. Value (Bightness) of the colour. Values that overshoot will be truncated. |
HSL360 ( hue, saturation, lightness)
HSV360 ( hue, saturation, value)
Allows HSL
and HSV
to be called with values that ranged in [0,360)
, [0,100]
and [0,100]
respectively that will make some users to feed parameters more coveniently.
RandomColor ()
Return a random colour that is evenly distributed over the RGB color space.
RandomColorHSL ()
Return a random colour that is evenly distributed over the HLS color space.
RandomColorHSV ()
Return a random colour that is evenly distributed over the HSV color space.\