Archive for August, 2012
At times it can be nice to define you own colors in charts. You may need to use a specific a corporate color scheme, make it easier to tell certain items apart or simply make the chart easier for the user to understand quickly.
It has always puzzled me how they chose the colors for some of the out-of-the-box system charts in Microsoft Dynamics CRM 2011.
Take the “Cases by Priority” chart for example.
At first glace this chart seems alright. Except when you look at how the series are colored, cases with “Normal” priority are red. In a chart like this red stands out more and most users would associate the red color with some kind of warning sign. On the other hand, the cases with priority high has the less alarming color blue.
Before we get into changing this specific chart, let’s look at some of our options for changing and modifying specific colors.
Export the charts xml file, open it and find the PaletteCustomColors property.
All the colors are listed as RGB colors, separated by a semicolon.
While Dynamics CRM add RGB colors to its custom palette it should be noted that Dynamics CRM accepts
- RGB Decimal (example: 97,142,206)
- RGB HEX (example: #4169E1)
- Named colors (example: Blue)
- ARGB (127,97,142,206)
The named colors could prove a lot easier to work with.
So instead of PaletteCustomColors=”97,142,206; 209,98,96; 168,203,104; etc.
we could write PaletteCustomColors=”Blue; Red; Green; etc.
Using the color names also makes it a lot easier to check if you have added them in the correct order.
This page contains an overview of the named colors available to use in charts.
Bonus: There’s one color missing from this list and that is “Transparent”. Transparent could prove very useful when you need to add data to a chart, but actually don’t want to show it. For example you may only want to display the value on a chart, but not have the bar or column visible.
Back to the example where we wanted to change the color scheme so High Priority Cases are red and Normal Priority Cases are Blue.
Since Dynamics CRM lists the series in reverse order (right to left) we know that Blue is the first color and therefore goes to the series for High Priority.
We want to change the the order of the colors so Red gets the first High Priority series. Then Blue and then Green.
Importing it back into Dynamics CRM we will get this result for the Cases By Priority Chart.
Now the High priority cases are appropriately Red and the Normal and Low priority cases have less alarming colors.
On some charts it is also possible to add specific colors to specific series, but I’ll save that for a later blog post.
Charts also support ARGB, which is similar to RGB, but there’s four values instead of three. The first value indicates the color’s Alpha transparency. 0 equals completely transparent. 255 is no transparency. 127 is 50% transparent etc.
Alpha transparency values are normally a percentage, but it has to be written in the RGB format which is a value between 0 and 255.
One of my pet peeves about sorting data in charts is, that the proper order for the viewer, may not always be alphabetic or numbers ascending or descending. A prime example of this is Territories. I often see three territories used. West, Central and East. When viewing them on a chart, they often appear like this.
At first glance that seems ok, but a part of visualizing data is making it easy to decode for the viewer. Especially in demo situations. If looking at the names of a few geographically dispersed territories like this, you would assume the data is being presented in the same order as if you were looking at them on a map. Unfortunately there’s no way to alphabetically sort Central, East and West so they appear in the preferred order of West, Central, East.
Now, we could just add an introducing letter or number to each name so they would sorted like we wanted, but having “A. West”, “B. Central” and “C. East” just doesn’t look good and we don’t want to add irrelevant information to our charts. Besides, that would just be way too easy.
There are two methods to achieve this, so you can pick the one that fits your needs the best.
1. Custom Sort Field on the linked entity
Now what I want to do is
- Remove the Legend (1,2,3) as we do not need to display the sort order
- Change the chart type to StackedColumn
- Remove the funky coloring
That may just work in case I want to have different colors to my territories. The different colors show up because the chart is coloring according to the Sort Order field, so they are actually representing 3 different series.
2. Utilize the Option Set value sorting
This method utilizes the fact that if an Order is not specified in the xml and an Option Set is used, then the Chart orders your data based on the Value of the Option Set and not the Label.
In the Territory example I’ve added a new option set to replace the name field. I’ve added all the Territory names and and I can now set the name for each Territory record through the Option Set.
All I need to make sure is that the Values are in the order that I desire.
Again, now a much more pleasant order of Territories.
This method is definitely easier and quicker to implement, but it also assumes that you are working with reasonably few names and that you can implement the Option Set and ensure its values are updated properly.
The Order of which a series is displayed can be a little tricky to work with. If no order is defined in the chart, the chart will display your data according to the sort order defined in the View that you are using. So excluding the order clause from the chart can give you a more dynamic way of adjusting your charts, as you won’t need to do xml customizations. Relying on the view also limits your sorting options to name fields or dates. I.e. you cannot use the View settings to order on aggregated fields.
However, it is often needed to specify one or more order clauses to make sure your data is presented properly.
To specify how data is ordered, or sorted, we utilize the Order clause in the fetchcollection in the xml.
In this example I have added two order clauses to a case chart.
The first line is the primary sort order and the following line is the secondary sort order. That way you can control the sort orders by adding the order clauses in the correct order. That was too many “orders” for one sentence.
- Order clauses can only be set for fields on the primary entity
- When using option sets as the basis of a series, the series get ordered according to the value of the option set and not its label. However, it seems that this only applies if an order clause has not been added to the fetchcollection
- More info on MS website can be found here http://msdn.microsoft.com/en-us/library/gg309565.aspx#orderby_aggregate
- If you need to sort on a linked entity, please see this blog post
When creating charts in Dynamics CRM, CRM creates a custom palette. However, it is the same custom palette that is being used on all you charts. So when you have dashboards with charts displaying data from different entities or different types of data, it can be difficult for the user to tell the information apart when everything is red, green and blue.
Fortunately it is fairly easy to export the charts xml file and modify it to display different color schemes, or Palettes as they are called. The Palette settings can be found right in the beginning of the presentationdescription. A quick search for “Palette” in your favorite xml editor (mine is Notepad++) will help you find it.
To apply a Palette, delete the cusot colors and replace “None” with one of the available Palette names. Before we start changing things, there a couple of things that are good to know about Palettes
- They contain 16 colors – if you have more than 16 series in a chart, the colors start repeating after 16
- The custom palette that CRM adds to charts have 12 colors
- If Palette is “None” and there are no custom colors, then the Palette “BrightPastel” is used
- If Palette is used, it will take precedence over your palette custom colors
The 12 different palettes available can be found here http://msdn.microsoft.com/en-us/library/system.web.ui.datavisualization.charting.chartcolorpalette.aspx
The options available are
- BrightPastel (the default if set to “None”)
Unfortunately Microsoft doesn’t seem to provide a graphical overview of the colors included, so here’s some samples to give you an idea of the color schemes.
The series is numbered 1-9 and are sorted in the same order. Meaning series 1 is the first color awarded etc. I am using a stacked column chart which shows the series in reverese order. Not sure why that is the default setting for a stacked chart. I figured 9 colors was enough to get an idea of what the palette looks like.
You are probably familiar with this color scheme by now.
Interesting that this is the only Palette that features a scale that gradually increases from light to dark. This might have been useful with other colors too.
But WHY!!!!! – Well, if you really like the Excel color scheme.
If you look closely you can see the gridlines though the columns. This may be more interesting to use on area charts or radar charts.