SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Multiple Color Palettes in SSRS


Multiple Color Palettes in SSRS

Author
Message
msoutherland
msoutherland
SSC Journeyman
SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)

Group: General Forum Members
Points: 87 Visits: 228
Hi,

The code below works great for a single client custom color palette.


Private colorPalette As String() = {"#376092", "#939393", "#90c226", "#000982", "#009470",
"#8064a2", "#a9d08e", "#266dbc", "#666666", "#71a739",
"#8eb4e3", "#610085", "#93cddd", "#277586", "#2d9d2f",
"#95b3d7", "#85003b", "#dbdbdb", "#4395ff", "#ab7dff",
"#009470", "#b4c6e7", "#af0073"}
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


However, I'd like to be able to get the color values from a database table based on a parameter. The db table has PaletteName (which is also a parameter I created) and Color1, Color2,....Color25. Rather than having the colors hardcoded in the above code colorPalette,
I'd like to populate them with the values from my generic Color field names in the db table.

I think it would look something like:

Private colorPalette As String() = {Color1, Color2, Color3, Color4, Color5, Color6, Color7, Color8, Color9, Color10, Color11, Color12, Color13, Color14, Color15, Color16, Color17, Color18, Color19, Color20, Color21, Color22, Color23, Color24, Color25 }


I hope this is making sense & someone can help.

Thanks,

Michele
Spiff
Spiff
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1702 Visits: 2234
Hi Michele,

I'm actually doing something very similar currently. My code wasn't as nice though.

What I did was to add my Palette table as a dataset then used a Lookup for the returned colour string e.g. "Color1" from my palette dataset.

So the formula for the colour would look like:


=Lookup(Code.GetColor("Group1"), Fields!ColorName.Value, Fields!ColorRGB.Value,"Palette_Dataset")



Or alternatively you could add the dataset and and use code to generate the list (see code below).

Create a table using your palette dataset and delete all but one detail textbox. In that detail textbox set the Visible properties to be show or hide based on an expression and set the expression to =getPallete(Fields!Value.Value). Since it always returns true it will always be hidden but it adds the elements to the new list.

Below that call setColorPalette() in a textbox to work to setup your color list and after this you should be able to use getColor as normal.

I've attached a sample to demonstrate. (UPDATED SAMPLE)


Private colors As New System.Collections.Generic.List(Of String)()
Private colorPalette As String()
Private count As Integer = 0
Private mapping As New System.Collections.Hashtable()


Public Function getPalette(a as string) As Boolean
colors.Add(a)
Return true
End Function

Public Function setColorPalette() As String
colorPalette = colors.ToArray()
return ""
End Function

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



Let me know if you have any questions.
Attachments
Report5.zip (25 views, 2.00 KB)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search