我之所以能够解决这个问题,是因为我使用的是一个自定义调色板,它被实现为一个哈希表。我基本上序列化了这些信息,并将其传递给子报表上的隐藏参数,然后重新展开数据结构。
这不是完美的,但它现在有效。
' 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
. 我当时很着急,所以我很快就把它们转换成一个数组。代码来自
Collection Serialization in ASP.NET Web
Services
马克·里奇曼写的文章。我将代码从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个级别的钻取,并且工作正常。