0

Is it possible to set textbox font color using HSL values in an SQL Server Reporting Services report? Is it possible to use expression that turns HSL values into a HTML color code supported by SSRS? For example hsl(77, 19%, 76%) equals #c7cdb6.

jumxozizi
  • 562
  • 8
  • 19

3 Answers3

1

Go to "Report Properties" > Code and add following custom code:

Public Function hsl2htmlColor(ByVal h as Double, ByVal s as Double, ByVal l as Double) as string
    dim r as Double
    dim g as Double
    dim b as Double

    If s = 0 Then
        r = g = b = l
    Else
        dim q as Double

        If l < 0.5 Then 
            q = l * (1 + s) 
        Else
            q = l + s - l * s 
        End If

        dim p as Double = 2 * l - q
        r = hue2rgb(p, q, h + 1/3)
        g = hue2rgb(p, q, h)
        b = hue2rgb(p, q, h - 1/3)
    End If

    return "#" & right("00" & Hex(r * 255) , 2) & right("00" & Hex(g * 255) , 2) & right("00" & Hex(b * 255) , 2)
End Function

Public Function hue2rgb(ByVal p as Double, ByVal q as Double, ByVal t as Double) as Double
    If t < 0    Then t += 1
    If t > 1    Then t -= 1
    If t < 1/6  Then return p + (q - p) * 6 * t
    If t < 1/2  Then return q
    If t < 2/3  Then return p + (q - p) * (2/3 - t) * 6
    return p
End Function

(example) Go to your text box properties and add following expression to Font > Color. The scale for each argument is from 0 to 1.

=Code.hsl2htmlColor(0.268 , 0.389 , 0.476)
jumxozizi
  • 562
  • 8
  • 19
0

It is not possible specify colors in SSRS using HSL coordinates but you can create a custom function to get the RGB values and use the SSRS RGB function to get the color.

In this link there is a JavaScript algorithm to convert HSL to RGG. I'd translate that code to a VB function that returns an array [R,G,B] object containing RGB values, then just call the function with the HSL values as args.

=RGB(Code.HSL2RGB(h,s,l)[0],Code.HSL2RGB(h,s,l)[1],Code.HSL2RGB(h,s,l)[2])

If you don't know how to create a custom function check this

Let me know if this helps.

alejandro zuleta
  • 13,357
  • 3
  • 25
  • 46
0

Not Sure if HSB can fullfill your need.

Right Click>Textbox Properties>Fill>Fill Color>More Color

enter image description here

p2k
  • 2,028
  • 4
  • 21
  • 37
  • I am unsure but I think HSL is different to HSB, maybe OP means HSB though. – alejandro zuleta Aug 26 '16 at 18:00
  • From Wikipedia: "HSL stands for hue, saturation, and lightness (or luminosity), and is also often called HLS. HSV stands for hue, saturation, and value, and is also often called HSB (B for brightness)." Similar but can be converted: http://stackoverflow.com/questions/3423214/convert-hsb-hsv-color-to-hsl – Hannover Fist Aug 26 '16 at 20:57
  • Thanks for pointing this out. Unfortunately when I pick a color it will just hard code the HTML code. So it's no use when automating things. – jumxozizi Aug 29 '16 at 07:42