jumxozizi
jumxozizi

Reputation: 649

SSRS HSL color expression

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.

Upvotes: 0

Views: 1066

Answers (3)

jumxozizi
jumxozizi

Reputation: 649

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)

Upvotes: 1

Pintu Kawar
Pintu Kawar

Reputation: 2156

Not Sure if HSB can fullfill your need.

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

enter image description here

Upvotes: 0

alejandro zuleta
alejandro zuleta

Reputation: 14108

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.

Upvotes: 0

Related Questions