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 assigned. This is fine if you don’t want any control over what colors are used. Or don’t care what the end result looks like. In all of Recast’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 Recast. Then 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.

I have 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 Recast:

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.

colorPalette is defined as an array of strings. Each string is a color, so each one forms part of my color palette.

Do no mix and match color name and color codes. 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 why I highly recommend that you use Hex Color codes exclusively. This is to ensure that you always get the correct color.

Next, there is a variable called, “count As Integer.” What the name is self explanatory.

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. When one already exists, the color code is returned. Else the next color code on the list is returned.

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 function 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!

Need help creating a color palette? Please read, How to Choose a Color Palette for SCCM Reports 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.