SSRS 颜色渐变
SSRS Color Gradient
我已经能够弄清楚如何使某些值成为我想要的某些颜色。但是,我真的很想能够创建一个颜色渐变,以便它更像是每个值之间的渐变。
0 = 白色
从白色到绿色在 1 到 15 之间,
从绿色到黄色的梯度在 16 到 25 之间,
和从黄色到红色的渐变在 26 和 35 之间,
任何超过 35 的都是红色。
这是我在后台填充表达式中的代码:
=SWITCH(
(Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value)) = 0, "White",
((Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value)) >= 1 and
(Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value)) <= 15), "Green",
((Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value)) >= 16 and
(Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value)) <= 25), "Yellow",
((Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value)) >= 26 and
(Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value))) <= 35, "Orange",
(Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value)) > 35, "Red")
This is the matrix I have so far
看看我前阵子写的这个回答。是做图表的,原理应该是一样的。
基本思路是在SQL中计算颜色,然后用它来设置SSRS
中的颜色属性
Applying Custom Gradient to Chart Based on Count of Value
将其全部保存在 SSRS 中
如果您想将其保留在报告中,您可以编写一个函数来进行计算。
对于一个非常简单的红色渐变,它可能看起来像这样..
Public Function CalcRGB (minVal as double, maxVal as double, actualVal as double) as String
Dim RedValue as integer
Dim GreenValue as integer
Dim BlueValue as integer
RedValue = ((actualVal - minVal) / (maxVal - minVal)) * 256
GreenValue = 0
BlueValue = 0
dim result as string
result = "#" & RedValue.ToString("X2") & greenValue.ToString("X2") & BlueValue.ToString("X2")
Return result
End Function
在这个函数中,我将绿色和蓝色设置为 0,但这些也可以根据需要计算。
要将此函数用作背景颜色,请将背景颜色 属性 设置为
=Code.CalcRGB(
MIN(Fields!myColumn.Value),
MAX(Fields!myColumn.Value),
Fields!myColumn.Value
)
我已经能够弄清楚如何使某些值成为我想要的某些颜色。但是,我真的很想能够创建一个颜色渐变,以便它更像是每个值之间的渐变。
0 = 白色
从白色到绿色在 1 到 15 之间,
从绿色到黄色的梯度在 16 到 25 之间,
和从黄色到红色的渐变在 26 和 35 之间,
任何超过 35 的都是红色。
这是我在后台填充表达式中的代码:
=SWITCH(
(Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value)) = 0, "White",
((Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value)) >= 1 and
(Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value)) <= 15), "Green",
((Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value)) >= 16 and
(Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value)) <= 25), "Yellow",
((Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value)) >= 26 and
(Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value))) <= 35, "Orange",
(Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value)) > 35, "Red")
This is the matrix I have so far
看看我前阵子写的这个回答。是做图表的,原理应该是一样的。
基本思路是在SQL中计算颜色,然后用它来设置SSRS
中的颜色属性Applying Custom Gradient to Chart Based on Count of Value
将其全部保存在 SSRS 中
如果您想将其保留在报告中,您可以编写一个函数来进行计算。
对于一个非常简单的红色渐变,它可能看起来像这样..
Public Function CalcRGB (minVal as double, maxVal as double, actualVal as double) as String
Dim RedValue as integer
Dim GreenValue as integer
Dim BlueValue as integer
RedValue = ((actualVal - minVal) / (maxVal - minVal)) * 256
GreenValue = 0
BlueValue = 0
dim result as string
result = "#" & RedValue.ToString("X2") & greenValue.ToString("X2") & BlueValue.ToString("X2")
Return result
End Function
在这个函数中,我将绿色和蓝色设置为 0,但这些也可以根据需要计算。
要将此函数用作背景颜色,请将背景颜色 属性 设置为
=Code.CalcRGB(
MIN(Fields!myColumn.Value),
MAX(Fields!myColumn.Value),
Fields!myColumn.Value
)