Reporting services 在Reporting Services 2005中,如何保持不同图表的颜色一致?
我使用TechNet为我的图表创建了一个自定义调色板 我还有一系列的钻取柱形图,单击其中一列,它会将一个参数传递到下一个图表,以此类推,给出了向下钻取的外观 我的图表由三种类型的劳动力组成,主图表上有三种颜色。当我深入到下一张图表时,一些类别并没有主类别所拥有的全部三种类型的劳动力。因此,调色板中的第一种颜色被指定给该系列,即使它是上一张图表中的第二种颜色。如果可能的话,我想避免这种情况 因此,数据值在第一个图表上为绿色(颜色顺序中的第二个),在下一个图表上为黄色(颜色顺序中的第一个)。如何让图表“记住”第一张图表中的系列组总数Reporting services 在Reporting Services 2005中,如何保持不同图表的颜色一致?,reporting-services,reportingservices-2005,Reporting Services,Reportingservices 2005,我使用TechNet为我的图表创建了一个自定义调色板 我还有一系列的钻取柱形图,单击其中一列,它会将一个参数传递到下一个图表,以此类推,给出了向下钻取的外观 我的图表由三种类型的劳动力组成,主图表上有三种颜色。当我深入到下一张图表时,一些类别并没有主类别所拥有的全部三种类型的劳动力。因此,调色板中的第一种颜色被指定给该系列,即使它是上一张图表中的第二种颜色。如果可能的话,我想避免这种情况 因此,数据值在第一个图表上为绿色(颜色顺序中的第二个),在下一个图表上为黄色(颜色顺序中的第一个)。如何让图
这是Reporting Services 2005。不幸的是,这是不可能的。我已经找了很长时间了…您无法使用自定义调色板修复此问题
您可以在数据库中为人工类型指定颜色(使用十六进制最简单)。然后将其传入数据集中。然后将颜色属性设置为十六进制值 我之所以能够解决这个问题,是因为我使用了一个自定义调色板,作为哈希表实现。我基本上序列化了这些信息,并将其传递给子报表上的一个隐藏参数,然后重新格式化数据结构 它并不完美,但目前还可以用
' Define some globals, including the color palette '
Private colorPalette As String() = _
{"#FFF8A3", "#A9CC8F", "#B2C8D9", "#BEA37A", "#F3AA79", "#B5B5A9", "#E6A5A4", _
"#F8D753", "#5C9746", "#3E75A7", "#7A653E", "#E1662A", "#74796F", "#C4384F", _
"#F0B400", "#1E6C0B", "#00488C", "#332600", "#D84000", "#434C43", "#B30023"}
' color palette pulled from SAP guidelines '
' http://www.sapdesignguild.org/resources/diagram_guidelines/color_palettes.html '
Private count As Integer = 0
Private colorMapping As New System.Collections.Hashtable()
' Create a custom color palette '
Public Function GetColor(ByVal groupingValue As String) As String
If colorMapping.ContainsKey(groupingValue) Then
Return colorMapping(groupingValue)
End If
Dim c As String = colorPalette(count Mod colorPalette.Length)
count = count + 1
colorMapping.Add(groupingValue, c)
Return c
End Function
' In custom actions of the data value, set the results of this '
' function to the mapping parameter in the next report '
Public Function PassColorMapping() As String
If colorMapping.Count = 0 Then
Return Nothing
End If
Try
' convert the hashtable to an array so it can be serialized '
Dim objHash As Object()() = ToJaggedArray(colorMapping)
' serialize the colorMapping variable '
Dim outStream As New System.IO.StringWriter()
Dim s As New System.Xml.Serialization.XmlSerializer(GetType(Object()()))
s.Serialize(outStream, objHash)
' move on to the next report '
Return outStream.ToString()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
我遇到了一个问题,无法找到与报告的onLoad事件等效的事件。因为我不确定把这个充气代码放在哪里,我把它贴在绘图区域的背景色上。所以我总是回“白烟”。如果我能找到合适的地方,我会把它换掉
' Call this function when the report loads to get the series groups '
' that have already been loaded into the custom color palette '
' Pass in the parameter used to store the color mapping '
Public Function InflateParamMapping(ByVal paramMapping As Parameter) As String
Try
If paramMapping.Value Is Nothing Then
Return "WhiteSmoke"
ElseIf colorMapping.Count = 0 Then
Dim pXmlized As String = paramMapping.Value
' deserialize the mapping parameter '
Dim s As New System.Xml.Serialization.XmlSerializer(GetType(Object()()))
' get the jagged array and convert to hashtable '
Dim objHash As Object()() = DirectCast(s.Deserialize(New System.IO.StringReader(pXmlized)), Object()())
' stick the result in the global colorMapping hashtable '
colorMapping = ToHashTable(objHash)
count = colorMapping.Count
End If
Catch ex As Exception
' MsgBox(ex.Message) '
End Try
Return "WhiteSmoke"
End Function
ToJaggedArray()
和ToHashTable()
都是帮助函数,因为哈希表实现了IDictionary
,所以不能序列化。我很匆忙,所以我很快就把它们转换成了一个数组。代码来自马克·里希曼的文章。我将代码从C#转换为VB.NET,以便在报告中使用
Public Function ToJaggedArray(ByVal ht As System.Collections.HashTable) As Object()()
Dim oo As Object()() = New Object(ht.Count - 1)() {}
Dim i As Integer = 0
For EAch key As Object in ht.Keys
oo(i) = New Object() {key, ht(key)}
i += 1
Next
Return oo
End Function
Public Function ToHashTable(ByVal oo As Object()()) As System.Collections.HashTable
Dim ht As New System.Collections.HashTable(oo.Length)
For Each pair As Object() In oo
Dim key As Object = pair(0)
Dim value As Object = pair(1)
ht(key) = value
Next
Return ht
End Function
现在在报告中,你需要做几件事
- 在两个报告的报告属性中添加对
的引用System.Xml
- 在父报表的操作中,将包含数据结构的参数设置为
=code.PassColorMapping()
- 在报告的绘图区域部分,将以下表达式作为背景:
=code.InflateParamMapping(Parameters!colorMapping)
- 当然,在两个图表上的数据系列样式的填充中,使用以下表达式:
=code.GetColor(Fields!Type.Value)
您可以继续对任意多个子报表执行此操作-我目前有3个钻取级别,效果很好。我非常轻松地解决了这个问题 在我的父报表中,我有12个系列字段,每个字段在图表中都有自己的颜色,在我的子报表中,我只保留图表上的所有系列,例如使用向下钻取从柱状图到折线图,但我控制它们的可见性 因此,在系列属性->可见性中的子报告中,我只添加了一个表达式: =(字段!ContentType.Value参数!ContentType.Value)
这样,报告只会保持单击值的可见性,并隐藏所有其他值,颜色保持不变:)您的评论让我非常难过。当然,一定有一种自定义代码的方法…如果你找到了,请让我知道…我过去不得不这样做,但找不到任何解决方案。当然。它不是最漂亮的,但是我不知道你打算怎么做,如果你不想办法给一个劳动力类型分配颜色的话。你必须在它被分配到任何子报表之前分配颜色。好吧,我活该。现在想想,我想我可以把序列顺序存储在数据库中,然后用这个数字来查找颜色。当然,这肯定还需要清理。但最好不要碰我的数据库模式和查询。