SSRS Report Builder 3.0:条件格式渐变颜色

时间:2015-08-27 11:36:17

标签: conditional-formatting ssrs-2012 ssrs-tablix reportbuilder3.0 reportbuilder

我可以找到很多关于如何在Report Builder 3.0中使用tablix字段的条件格式的教程。但是我想要一个创建渐变颜色的函数,从黑色到红色,它会使文本颜色越来越红,越接近某个数字。

例如,我在一天内得到了一个产品组件年龄的列。当组件为0天时,我希望文本为黑色(#000000)。然后逐渐变成红色,在它到期的那天(可能是第30天)击中纯红色(#FF0000)

任何人都可以向我提供有关如何操作的信息吗?

1 个答案:

答案 0 :(得分:2)

我最终修改了Alejandro链接的解决方案中的功能。

Public Shared Function ColorDWB(ByVal Value As Decimal, ByVal MaxPositive As Decimal, ByVal Neutral As Decimal, ByVal ColStr As String) As String

'Initiate variables for Red, Green and Blue (RGB)
Dim ColVar1 As Integer
Dim ColVar2 As Integer
Dim ColVar3 As Integer

'Split the #RGB color to R, G, and B components
ColVar1=Convert.ToInt32(left(right(ColStr, 6),2),16)
ColVar2=Convert.ToInt32(left(right(ColStr, 4),2),16)
ColVar3=Convert.ToInt32(right(ColStr, 2),16)

'Find Largest Range
Dim decPosRange As Decimal = Math.Abs(MaxPositive - Neutral)

Dim iColor1 As Integer
Dim iColor2 As Integer
Dim iColor3 As Integer 
Dim strColor As String

'Reduce a shade for each of the R,G,B components
iColor1 = Math.Max(0, Math.Min(ColVar1, ColVar1*(Value-Neutral)/(MaxPositive-Neutral)))
iColor2 = Math.Max(0, Math.Min(ColVar2, ColVar2*(Value-Neutral)/(MaxPositive-Neutral)))
iColor3 = Math.Max(0, Math.Min(ColVar3, ColVar3*(Value-Neutral)/(MaxPositive-Neutral)))

'Return the new color
strColor = "#" & iColor1.ToString("X2") & iColor2.ToString("X2") & iColor3.ToString("X2") 
Return strColor
End Function