SSRS 2013热图

时间:2016-06-22 20:22:15

标签: visual-studio reporting-services heatmap

软件:MS Visual Studio Shell 2013

我目前正在研究我试图发布的SSRS报告的矩阵热图。

我尝试应用背景的文本框按行和列分组。它有一个count函数来确定该单元格的值。

我使用的报告代码是:

public const ColorScaleRed = "#FF0000"
public const ColorScalePink= "#ff6666"

public function ColorScaleWPR(value, minValue, maxValue) as string

    ColorScaleWPR = ColorScale3(value, _
        minValue, "White", _
        ColorScalePink, _
        maxValue, ColorScaleRed)

end function

public function ColorScale3(value as object, minValue as object, minColor as string, midColor as string, maxValue as object, maxColor as string) as string

    ' Use average of minValue and maxValue as midValue
    dim midValue as object
    if IsNumeric(minValue) and IsNumeric(maxValue) then
        midValue = (CDbl(minValue) + CDbl(maxValue)) / 2
    end if

    ColorScale3 = ColorScale3(value, _
        minValue, minColor, _
        midValue, midColor, _
        maxValue, maxColor)

end function

public function ColorScale3(value as object, minValue as object, minColor as string, midValue as object, midColor as string, maxValue as object, maxColor as string) as string

    if IsNumeric(value) and IsNumeric(midValue) and CDbl(value) < CDbl(midValue) then
        ColorScale3 = ColorScale(value, minValue, minColor, midValue, midColor)
    else
        ColorScale3 = ColorScale(value, midValue, midColor, maxValue, maxColor)
    end if

end function

public function ColorScale(value as object, minValue as object, minColor as string, maxValue as object, maxColor as string, optional errorColor as string = "Transparent") as string

    ColorScale = errorColor

    if not IsNumeric(value) or not IsNumeric(minValue) or not IsNumeric(maxValue) then
        exit function
    end if

    ' Do all calculations using doubles (can't mix doubles and decimals)
    value = CDbl(value)
    minValue = CDbl(minValue)
    maxValue = CDbl(maxValue)

    if minValue >= maxValue then
        exit function
    end if

    if value <= minValue then
        ColorScale = minColor
        exit function
    end if
    if value >= maxValue then
        ColorScale = maxColor
        exit function
    end if

    dim scaleValue, r, g, b as double
    dim minRGB, minR, minG, minB as integer
    dim maxRGB, maxR, maxG, maxB as integer

    scaleValue = (value - minValue) / (maxValue - minValue)

    minRGB = GetRGB(minColor)
    minR = minRGB / 2^16
    minG = (minRGB mod 2^16) / 2^8
    minB = minRGB mod 2^8

    maxRGB = GetRGB(maxColor)
    maxR = maxRGB / 2^16
    maxG = (maxRGB mod 2^16) / 2^8
    maxB = maxRGB mod 2^8

    r = minR + ((maxR - minR) * scaleValue)
    g = minG + ((maxG - minG) * scaleValue)
    b = minB + ((maxB - minB) * scaleValue)

    ColorScale = string.Format("#{0:X2}{1:X2}{2:X2}", _
        CInt(Math.Floor(r)), _
        CInt(Math.Floor(g)), _
        CInt(Math.Floor(b)))

end function

private function GetRGB(colorStr as string) as integer

    GetRGB = 0

    if colorStr.StartsWith("#") then
        GetRGB = Int32.Parse(colorStr.Substring(1), System.Globalization.NumberStyles.AllowHexSpecifier)
        exit function
    end if

    dim c as System.Drawing.Color
    c = System.Drawing.Color.FromName(colorStr)

    GetRGB = (c.R * 2^16) + (c.G * 2^8) + c.B

end function

我的问题是当我设置背景表达式时。

我能够使用以下表达式正确渲染热图:

=Code.ColorScaleWPR(Count(Fields!Candidate_ID.Value),0,10)

但是,我不想为最小值和最大值使用静态值。我希望它们是动态的,因为根据所选择的参数,这些最小值和最大值可能会有很大差异。

所以我使用了以下代码

=Code.ColorScaleWPR(Count(Fields!Candidate_ID.Value), Min(Fields!Candidate_ID.Value,"DataSet1"), Max(Fields!Candidate_ID.Value,"DataSet1"))

当我运行报告时,它呈现完全白色,并且没有任何条件应用于细胞。

任何让它变得动态的建议都会很棒。 谢谢!

1 个答案:

答案 0 :(得分:0)

我认为RS不能预先计算所有分组,然后从中找到最小值/最大值以应用色标。  尝试的最佳方法是将每个组的最小值和最大值计算为与原始数据集查询分开的数据集。然后使用表达式基于匹配的组标准拉出所需的值。我会朝那个方向走...... PS。当我在旋转矩阵分组上使用色阶时,我没有足够的时间让这个野兽活着我的情况:)