How to make cell background color continuous red <--> green based on value?
-
Friday, February 15, 2013 12:38 PM
Hi all,
I have a column in my report that takes on float values, both positive and negative. Currently I'm using iif statements to have the background color of a cell take on either red, green, or yellow, depending on which of 3 intervals the cell's value falls into.
It would be slicker if I could make the background color continuously "fade" between those three "perfect" values, depending on the exact value of the cell.
Can this be done? How?
Thanks for any suggestions,
sff
All Replies
-
Friday, February 15, 2013 12:46 PM
Hi,
Using the fill color? No fades unfortunately. But here's an idea:
Create the rectangular images with the different color fades between the three and then depending on your value, set this image as the textbox backgroundimage property.
Please mark as answered or vote helpful if this post help resolved your issue. Thanks!
k r o o t z -
Friday, February 15, 2013 1:38 PM
Hi, you cannot do that using the background color, however you could use a databar and configure this object to have a gradient color, and if you want, based on expressions, you could change the first color and the last color.
Regards
Regards | John Bocachica | MVP www.sqlgeek.net
-
Sunday, February 17, 2013 11:33 PM
Hi John,
Thanks for the reply.
Had a bit of time to come up with this, which satisfies my needs, and it's straightforward to see how to generalize it as needed. It takes parameters scaled to [0, 1] and spits out ssrs style hex rgb strings.
thanks again,
sff
Public Function RedYellowGreenFade(ByVal Value As Decimal) As String
'This function takes values on [0, 1] and converts to a fading red/yellow/green rgb color value
'To make this work for other colors, come up with your own damn parametric equation.
'To make this work for an arbitrary 3 colors, think harder.
'To make this work for an arbitrary number of arbitrary colors, think a even harder.
'Would also wanna include "inflection point" values when you improve this.
'Hell could lose the linear xform too and specify your own fade function, inflection point by inflection point
Dim red as Integer
Dim green as Integer
Dim blue as Integer
Dim strColor as String
If Value > .5 Then
red = Convert.toint32(255 * (1 - 2 * (Value - .5)))
green = 255
blue = 0
Else
red = 255
green = Convert.ToInt32(255 * 2 * Value)
blue = 0
End If
strColor = "#" & red.ToString("X2") & green.ToString("X2") & blue.ToString("X2")
Return strColor
End Function- Marked As Answer by sherifffruitfly2 Sunday, February 17, 2013 11:41 PM

