Chart Colors in Reporting Services
Hi all, Hopefully someone can clarify for me. I'd like to use custom colors for a chart that I have created. I've seen some code examples but I'm not really sure what to do with them. I've been using reporting services for like 2 days and I don't know xml or vb script, so I apologize for the probably stupid question. Thank you in advance. -Keith
May 21st, 2007 10:51pm

The answer is at http://msdn.microsoft.com/en-us/library/aa964128(SQL.90).aspx#moressrscharts_topic4 Quote: "To build a custom color palette Define the chart series groups and category groups. By default, every chart data series has a color assigned to it. This color is based on the selected chart palette. In this example, we want to override these colors based on the series group instance values. Define the custom color palette and add custom code. The colorPalette variable stores the definition of our custom color palette, which has 15 distinct colors. The count variable keeps track of the total count of distinct grouping values in order to wrap around once we exceed the number of distinct colors in the custom color palette. The mapping hash table keeps track of the mapping between grouping values and colors. This ensures that all data points within the same data series have the same color. Later it is used to synchronize the custom legend colors with the chart colors. The following code goes into the custom code window of the report. Copy Private colorPalette As String() = {"Green", "Blue", "Red", "Orange", "Aqua", "Teal", "Gold", "RoyalBlue", "MistyRose", "LightGreen", "LemonChiffon", "LightSteelBlue", "#F1E7D6", "#E16C56", "#CFBA9B"} Private count As Integer = 0 Private mapping As New System.Collections.Hashtable() Public Function GetColor(ByVal groupingValue As String) As String If mapping.ContainsKey(groupingValue) Then Return mapping(groupingValue) End If Dim c As String = colorPalette(count Mod colorPalette.Length) count = count + 1 mapping.Add(groupingValue, c) Return c End Function Call the GetColor() function to assign colors to data points. "
Free Windows Admin Tool Kit Click here and download it now
September 28th, 2010 10:57am

Just making it a bit more explicit 1) In BIDS, press Alt+R to open the Report Tab and select Report Properties. Then go to the code section and paste the following code Private colorPalette As String() = {"Green", "Blue", "Red", "Orange", "Aqua", "Teal", "Gold", "RoyalBlue", "#A59D93", "#B8341B", "#352F26", "#F1E7D6", "#E16C56", "#CFBA9B"} Private count As Integer = 0 Private mapping As New System.Collections.Hashtable() Public Function GetColor(ByVal groupingValue As String) As String If mapping.ContainsKey(groupingValue) Then Return mapping(groupingValue) End If Dim c As String = colorPalette(count Mod colorPalette.Length) count = count + 1 mapping.Add(groupingValue, c) Return c End Function Right now, there are only 14 colours in the palette but more colours can be added if you have more than 14 values in the series. 2) Use the following expression for colour in the fill tab of series properties (where OrdNum is the field Name based on which the color should change - replace with your field name). =Code.GetColor(Fields!OrdNum.Value) Cheers, Jason P.S. : Please click the 'Mark as Answer' button if a post solves your problem! :)
September 28th, 2010 11:22am

Modified code to include a reset parameter of the array when grouping across multiple pages. Call this function. where Row_number is the partition function in sql for thing you want to reset. =Code.GetColor(Fields![SeriesField].Value,Fields!Row_Number.Value) Code: Private colorPalette As String() = {"Blue", "Red", "Yellow", "Lime", "Aqua", "#E0861A", "#7C154D", "#E5A812", "#668237", "#00626D", "#BE4F24","#2C438A"} Private count As Integer = 0 Private mapping As New System.Collections.Hashtable() Public Function GetColor(ByVal groupingValue As String, ByVal reset As Integer) As String If reset = 1Then count = 0 End If If mapping.ContainsKey(groupingValue) Then Return mapping(groupingValue) End If Dim c As String = colorPalette(count Mod colorPalette.Length) count = count + 1 mapping.Add(groupingValue, c) Return c End Function enjoy!
Free Windows Admin Tool Kit Click here and download it now
January 29th, 2011 3:38pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics