如何在 Reporting Services 2005 中保持图表之间的颜色一致?

发布于 2024-08-18 02:18:10 字数 464 浏览 8 评论 0原文

我使用 a 为我的图表创建了自定义调色板TechNet 上描述的技术

我还有一系列钻取柱形图,您单击一列,它会将参数传递到下一个图表,依此类推,从而呈现出向下钻取的外观。

我的图表由 3 种类型的劳动组成,并且在主图表上有三种颜色。当我深入查看下一张图表时,某些类别并不包含主要类别所具有的全部三种类型的劳动力。因此,调色板中的第一种颜色被分配给该系列,即使它是上一个图表中的第二种颜色。如果可能的话,我想避免这种情况。

因此,数据值在第一个图表上为绿色(颜色顺序中的第二个),在下一个图表上为黄色(颜色顺序中的第一个)。如何使图表“记住”第一个图表中的系列组总数?

这是 Reporting Services 2005。

I created a custom color palette for my charts using a technique described on TechNet.

I also have a series of drill-through column charts, where you click on one column and it passes a parameter through to the next chart and so on, giving the appearance of drill-down.

My graphs consist of 3 types of labor, and have three colors on the main chart. When I drill down to the next chart, some of the categories do not have all three types of labor that the main one has. So the first color in the palette is assigned to the series, even though it was the second color on the previous chart. I'd like to avoid this, if possible.

So a data value is green on the first chart (2nd in the color order) and yellow on the next chart (1st in the color order). How do I make the graphs "remember" the total number of series groups that were in the first chart?

This is Reporting Services 2005.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

自找没趣 2024-08-25 02:18:10

您无法使用自定义调色板来修复此问题。

您可以做的是在数据库中为劳动力类型分配颜色(使用十六进制是最简单的)。然后将其传递到您的数据集中。然后将颜色属性设置为您的十六进制值。

You cannot fix this using custom colour palettes.

What you can do is assign the labour type a colour in the database (using HEX is easiest). Then pass that in in your data set. Then set the color property to you hex value.

过去的过去 2024-08-25 02:18:10

不幸的是这是不可能的。我找这个已经有一段时间了......

Unfortunately this is not possible. I've been looking for this for quite some time...

陌若浮生 2024-08-25 02:18:10

我之所以能够解决这个问题,是因为我使用了自定义调色板,以哈希表的形式实现。我基本上序列化了这些信息并将其传递给子报表上的隐藏参数,然后重新膨胀数据结构。

它并不完美,但目前可以使用。

' 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 事件等效的内容。由于我不确定将该膨胀代码放在哪里,因此我将其粘贴在绘图区域的背景颜色中。因此我总是返回“WhiteSmoke”。如果我能找到合适的地方放置它,我会更改它。

' 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() 是辅助函数,因为 HashTable 不可序列化,因为它们实现了 IDictionary。我很着急,所以我很快就把它们转换成了数组。代码来自 ASP.NET Web 中的集合序列化
服务
文章由 Mark Richman 撰写。我将代码从 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 个级别的钻取,并且它工作正常。

I was able to solve this because I was using a custom color palette, implemented as a hash table. I basically serialized this information and passed it to a hidden parameter on the subreport and then reinflated the data structure.

It's not perfect, but it works for now.

' 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

I ran into an issue where I couldn't find the equivalent of the onLoad event for the report. Since I wasn't sure where to put this inflate code, I stuck it in the background color of the plot area. Hence I always return "WhiteSmoke". I'll change this if I can find the right place to put it.

' 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() and ToHashTable() are helper functions because a HashTable is not serializable since they implement an IDictionary. I was in a hurry so I just converted them to an array right quick. Code comes from the Collection Serialization in ASP.NET Web
Services
article written by Mark Richman. I converted the code from C# to VB.NET to use in the report.

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

Now in the report itself you need to do a couple things.

  • Add a reference to System.Xml in Report Properties in both reports.
  • In the Actions of your parent report, set the Parameter containing your data structure to =Code.PassColorMapping()
  • In the Plot Area section of your report, put this expression for the background: =Code.InflateParamMapping(Parameters!colorMapping)
  • And of course, in the Fill for your data Series Style on both charts put this expression: =Code.GetColor(Fields!Type.Value)

You can continue doing this for as many subreports as you want - I currently have 3 levels of drill-through and it works fine.

苦妄 2024-08-25 02:18:10

我解决这个问题非常简单。

在我的父报告中,我有 12 个系列字段,每个字段在图表中都有自己的颜色,在我的子报告中,我只是将所有系列保留在图表上,例如使用向下钻取从柱形图到折线图,但我控制它们的可见性...

所以在系列属性的子报告中 ->可见性我只是添加一个表达式:
=(Fields!ContentType.Value <>Parameters!ContentType.Value)

这样,报表仅保留单击值的可见性并隐藏所有其他值,并且颜色保持不变:)

I solved that extremely easy.

In my parent report I have lets say 12 series fields, each one getting their own color in a chart, on my child report I just keep all series on the chart, for instance going from a column chart to a line chart using drill down, but I control the visibility of them...

So in the child report in Series Properties -> Visibility I just add an expression:
=(Fields!ContentType.Value <> Parameters!ContentType.Value)

This way the report only keeps the visibility of the clicked value and hides all the others and the colors remains the same :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文