Multiple Color Palettes in SSRS

  • 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

  • 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.

  • This was removed by the editor as SPAM

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply