2016-06-22 49 views
1

軟件:MS Visual Studio Shell 2013SSRS 2013熱圖

我目前正在爲我嘗試發佈的SSRS報告製作矩陣熱圖。

我試圖應用背景的文本框按行和列分組。它有一個計數功能來確定該單元格的值。我使用

報告準則是:

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")) 

當我運行它呈現全白的報告,並沒有調節的被應用於細胞。

任何建議,使其動態將是很棒的。 謝謝!

回答

0

我不認爲RS能夠預先計算所有分組,然後從它們中找出最小/最大值來應用色階。 要嘗試的最佳方法是將每個組的最小值和最大值計算爲來自原始數據集查詢的單獨數據集。然後使用表達式根據匹配的組標準提取所需的值。我會去那個方向...... PS。我沒有足夠的時間讓這個野獸在我的情況下活着,當我在旋轉矩陣組合上使用色階時::)