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

SSRS Report Builder 3.0: Conditional Formatting Gradient Color

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

例如,我得到一个列,其中包含产品组件的使用年限(以天为单位)。当组件存在 0 天时,我希望文本为黑色 (#000000)。然后逐渐变成红色,在到期的那天(可能是第 30 天)达到纯红色 (#FF0000)

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

我最终修改了 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

就像我之前的回答一样,那篇文章让我开始了,但我对其进行了修改以使其更适合我的目的。

Public Function HeatMap(ByVal Value As Double _
, ByVal MinVal As Double _
, ByVal MaxVal As Double _
, ByVal RValLo As Double _
, ByVal GValLo As Double _
, ByVal BValLo As Double _
, ByVal RValHi As Double _
, ByVal GValHi As Double _
, ByVal BValHi As Double _
) As String
Dim DiffPercent As Double
Dim RNew As Integer
Dim GNew As Integer
Dim BNew As Integer

Dim HeatMapColor As String
If Value = Nothing Then
    RNew = 255
    GNew = 255
    BNew = 255
ElseIf Value <= MinVal Then
    RNew = RValLo
    GNew = GValLo
    BNew = BValLo
ElseIf Value >= MaxVal Then
    RNew = RValHi
    GNew = GValHi
    BNew = BValHi
Else
    DiffPercent = (Value - MinVal) / (MaxVal - MinVal)
    RNew = RValLo - Round((RValLo - RValHi) * DiffPercent, 0)
    GNew = GValLo - Round((GValLo - GValHi) * DiffPercent, 0)
    BNew = BValLo - Round((BValLo - BValHi) * DiffPercent, 0)
End If

HeatMapColor = "#" & Hex(RNew) & Hex(GNew) & Hex(BNew)

   HeatMap = HeatMapColor
End Function

更多关于我的方法的信息: