【问题标题】:ssrs mapping chart colors to a categoryssrs 将图表颜色映射到类别
【发布时间】:2017-03-24 19:22:50
【问题描述】:

我有一个饼图和一个条形图,用于显示一些数据。我想将图表中的颜色映射到部门的特定颜色。 代码运行没有错误,但颜色并不总是映射到同一个部门。

此函数位于“代码”部分的报告正文中:

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 函数在每个图表的 Color 部分中作为表达式调用。

为什么映射依赖于查询返回的数据?

更新 我发现我的条形图是堆积的。当我只有 1 个部门时。在图表中,第一个条形图是“蓝色”,它是第一种颜色。第二个酒吧是勃艮第,这是第二种颜色。部门是系列分组。在此图表中,只有 2 个部门。当有2个部门时,颜色是正确的。

【问题讨论】:

  • 为什么不直接用ssrs中的表达式来设置颜色呢?
  • 如果我在代码中执行此操作,我只需执行一次,而不是在每个图表中编写 case 语句。

标签: reporting-services charts vbscript


【解决方案1】:

我想通了... 我需要在调用后添加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  

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-04
    • 1970-01-01
    • 2012-03-19
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    • 1970-01-01
    相关资源
    最近更新 更多