2017-03-24 17 views
0

我有一個餅圖和條形圖,我用來顯示一些數據。我想將圖表中的顏色映射到部門的特定顏色。 代碼無誤地運行,但顏色並不總是映射到同一個部門。ssrs映射圖表顏色到一個類別

此功能在「代碼」部分的報告正文:

Private mapping As New System.Collections.Hashtable() 
Private colorPalette As String() = {"#5badff", "#8c001a", "#a33247", "#ba6675", "#d199a3", "#e8ccd1"} 
Private boardNames As String() = {"Dept1", "Dept2", "App", "IT", "Delivery", "Development"} 

Public Function SetColorsToBoard() 
    Dim count As Integer = 0 
    Dim name As String = "" 

    IF colorPalette.Length = boardNames.Length Then 
     For Each name in boardNames   
      mapping.Add(name, colorPalette(count)) 
      count = count + 1 
     Next 
    End If 
End Function 

Public Function GetColor(ByVal groupingValue As String) As String 
    If mapping.ContainsKey(groupingValue) Then 
     Return mapping(groupingValue) 
    End If 
    Call SetColorsToBoard 
End Function 

如果有數據DEPT1按預期的方式顯示的顏色。當我選擇不同的公司並且他們在查詢中沒有Dept1時,Dept2被設置爲第一種顏色。 正如我試圖編寫函數,以便它不依賴於數據。

GetColor函數在每個圖表的顏色部分中作爲表達式調用。

爲什麼映射依賴於查詢返回的數據?

UPDATE 我發現我的條形圖是堆疊的。當我只有一個部門。在圖表中,第一個欄是第一個顏色的「藍色」。第二個酒吧是勃艮第,這是第二種顏色。該部門是系列分組。在這個圖表中只有2個部門。當有2個部門時,顏色是正確的。

+0

爲什麼不使用SSRS的表達直接設置顏色? – LONG

+0

如果我在代碼中做,我只需要做一次,而不是在每個圖表中寫入case語句。 –

回答

0

我想通了...... 我需要在調用映射後添加return mapping(groupingValue)。 這是GetColor功能:

Public Function GetColor(ByVal groupingValue As String) As String 
    If mapping.ContainsKey(groupingValue) Then 
     Return mapping(groupingValue) 
    End If 
    Call SetColorsToBoard 
    Return mapping(groupingValue) 
End Function