如何将SSRS渐变热力图的蓝红配色改为绿红配色?
修改SSRS热力图为绿红配色的VB函数调整方案
原代码的核心问题是正数分支的颜色通道设置错误,导致生成蓝白渐变而非绿白渐变。以下是修正后的完整VB.NET函数:
Public Function ColorRYG(ByVal Value As Decimal, ByVal MaxPositive As Decimal, ByVal MaxNegative As Decimal, ByVal Neutral As Decimal) As String 'Example: =code.ColorBack(expression, Max(expression), Min(expression), 0) '=code.colorback( Fields!Sales.Value,max( Fields!Sales.Value),min( Fields!Sales.Value),0) 'Find Largest Range Dim decRange As Decimal Dim decPosRange As Decimal = Math.Abs(MaxPositive - Neutral) Dim decNegRange As Decimal = Math.Abs(MaxNegative - Neutral) decRange = IIf(decPosRange > decNegRange, decPosRange, decNegRange) 'Force color into Max-Min Range. Important if you want to Clip the color display to a subset of the data range. Value = Switch((Value > MaxPositive), MaxPositive, Value < MaxNegative, MaxNegative, True, Value) 'Find Delta required to change color by 1/255th of a shade Dim decColorInc As Decimal = 255 / decRange 'Find appropriate color shade Dim iColor As Integer = CInt(Math.Round((Value - Neutral) * decColorInc)) 'Return Appropriate +ve or -ve color Dim strColor As String If iColor >= 0 Then 'Green to White gradient iColor = 255 - iColor 'Thus 0 = White & 255 = Green strColor = "#" & Math.Abs(iColor).ToString("X2") & "FF" & Math.Abs(iColor).ToString("X2") Else 'Red to White gradient iColor = iColor + 255 'NB iColour is -ve; -1 - -255 strColor = "#FF" & Math.Abs(iColor).ToString("X2") & Math.Abs(iColor).ToString("X2") End If Return strColor End Function
关键修改说明
- 正数分支(绿色渐变):将原代码中正数颜色生成语句修改为
strColor = "#" & Math.Abs(iColor).ToString("X2") & "FF" & Math.Abs(iColor).ToString("X2")。- RGB颜色格式为
#RRGGBB,修改后绿色通道(GG)固定为FF(255,纯绿),红(RR)和蓝(BB)通道随数值接近中性值从00递增到FF,实现从纯绿到白色的平滑过渡。
- RGB颜色格式为
- 负数分支(红色渐变):保持原有逻辑不变,红色通道(RR)固定为
FF,绿、蓝通道随数值接近中性值从00递增到FF,实现从纯红到白色的过渡。
替换原函数后,你的SSRS报表热力图将呈现**绿(高值)-白(中性)-红(低值)**的配色方案。
内容的提问来源于stack exchange,提问作者Chendo
相关产品推荐
相关产品推荐

