Color Palette Codes in SSRS Defined and Explained

This blog post is the first in a three-part set on how to create, use and synchronize color palette codes when using a chart, a table or a matrix in SQL Server Reporting Services (SSRS).

If you have ever written any reports in SSRS or Power BI, you know that when you create a chart or use color in a table, SSRS and Power BI automatically assign every color. This is fine if you don’t want any control over what colors are used and don’t care what the end result looks like. In all of Enhansoft’s reports, however, we never use the automatically assigned colors. Instead, we set the colors ourselves. In this blog post, I show you one of the color palette codes we use at Enhansoft and I explain what each part of the code means.

Why Define a Color Palette Code for SSRS?

There are many reasons you would want to define the colors used in a SSRS report. These include: making the information easier to read (e.g. matching the colors between a chart and a table), following style guides or adhering to Web Content Accessibility Guidelines (WCAG). We use our own custom color palettes to help customers understand data more quickly and easily.

Our Chief Architect has written a number of blog posts on why color is important, but here is a good one to start with, How Color Is Used in Power BI and SSRS Dashboards.

“The Code”

Here’s an example of a color palette code and function that we use at Enhansoft:

Private colorPalette As String() = {“#0f5fa9”, “#1aa755”, “#dd7e2d”, “#e9de3a”, “#915f39”, “#8361A8”, “#e01a1a”, “#2770b2”, “#31b066”, “#e08b42”, “#ece24f”, “#9c6f4c”, “#8f70b1”, “#CC9944”, “#DDDDCC”, “#AAAAAA”, “#776677”, “#FFCC44”, “#dddddd”, “#aa6699”, “#cc0022”, “#ddcccc”, “#999999”, “#dd7788”, “#ff0000”, “#ccbbbb”, “#ffaabb”, “#779944”, “#ddddcc”, “#778844”, “#88dd33”, “#99cc33”, “#55bbdd”, “#ccdddd”, “#aabbbb”, “#446688”, “#77ddff”, “#ccddee”, “#2288cc”, “#eeaa33”, “#bbaaaa”, “#995522”, “#ffcc33”, “#ff6600”, “#6655aa”, “#ddccdd”, “#554466”, “#8866cc”, “#773399”, “#667788”, “#ffcc55”, “#7799bb”, “#474152”, “#746820”, “#4A6F6E”, “#657320”, “#add8e6”, “#ff6347”, “#9acd32”, “#008080”, “#6495ed”, “#faa460”, “#ffd700”, “#00ff00”, “#A59D93”, “#8e4585”, “#B8341B”, “#352F26”, “#F1E7D6”, “#E16C56”, “#CFBA9B”, “#ffc0cb”, “#0000ff”, “#ff0000”}

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

“The Code” Explained

In order to create your own color palette code, you need to understand what is needed. I know when you first look at the code above, it is a bit of an eyechart, so let me break it down for you.

The first thing that you notice is that colorPalette is defined as an array of strings. Each string is a color, so each one forms part of my color palette.

In this example, HEX color codes are not mixed and matched with color names, but I’ve seen it done. In my opinion, this is a bad move because colour (UK spelling intended) names change based on what country you live in. You can read more about that in, When is Grey Not a Valid Color? which is also by our Chief Architect. I highly recommend that you use Hex Color codes exclusively in order to ensure that you always get the correct color.

Next, there is a variable called, “count As Integer.” This is a simple counter that is used within the function later on.

After that, “mapping” is defined as a “shortcut” to the System.Collections.Hashtable API function.

Now for the “meat and potatoes” of the code. The Enhansoft function, GetColor, at a high-level, accepts a string and then checks to see if there is already a defined color for that string. If one already exists, the assigned color is returned. If there isn’t a defined a color, the next color from the color palette is chosen and then assigned in the color code.

In the code above, the first color returned is #0f5fa9 and then #1aa755, etc. When the end of the color palette is reached (74 colors to be exact in this example) the code is designed to start over at the beginning with #0f5fa9.

The function is using simple math to define the color code.

How to Create Your Own Color Palette Code

Now that I explained the basics of a color palette code, you can get to work!

How to Choose a Color Palette for SCCM Reports is a great post to help you get started with choosing your own color palette. Once you decide what colors you want to use, you can simply edit each string in the code above by swapping out the HEX color code with your own choice.

Obviously, you can adapt the function for any number of predetermined instances. I plan to publish a blog post in the not too distant future that shows you how to modify the function.

Lastly, you need to add your color palette code to a report.

Adding the Code to a Report

Color Palette Code - Report Properties

From the menu, select Report and then click on Report Properties…

Color Palette Code - Code

Select the Code node and then paste the code with your color palette into the Custom code area. Click on the OK button.

With that last step completed, you are now ready to use your color palette! In next week’s blog post, you’ll see how to assign this color palette code to a chart. The following week, I show you how to match the colors between a chart and a table.

If you have any questions about color palette codes, you can reach out to me on Twitter @SuaresLeonard.

Showing 3 comments
  • firtuklo imutrzas
    Reply

    Heya i am for the first time here. I came across this board and I find It really useful & it helped me out much. I’m hoping to offer one thing back and help others like you helped me.

  • firtuklo imutrzas
    Reply

    Very interesting points you have noted, thank you for posting.

  • BrianLit
    Reply

    Many thanks very valuable. Will certainly share website with my buddies.

Leave a Comment

Share via
Copy link