How to: Specify Consistent Colors across Multiple Shape Charts

On non-Shape charts, a new color is selected from the palette based on the index of series in the chart. For example, the first series on your chart will be mapped to the first color in the palette. However, this behavior differs for Shape charts. On Shape charts, each color in the palette is mapped to a data point in the dataset. For example, data point 1 is mapped to the first color in the palette, data point 2 is mapped to the second color palette and so on.

If a data point has no value, it is omitted from display on a Shape chart. As such, the data point is not mapped to a palette color. For example, if point 2 has a value of zero, point 1 will be mapped to the first color in the palette, and point 3 will be mapped to the second color in the palette. This approach is useful because the empty points in the dataset of a pie chart do not unnecessarily use a palette color when the empty point does not need to be drawn.

As a side effect, when multiple pie charts are displayed in a report, the pie charts may display different colors for data points that have the same category grouping. To resolve this, you will need to define individual colors that map to a category group instead of individual data values.

The legend is connected to the series, so any color you specify for the series will automatically be shown on the legend.

To specify consistent colors across multiple Shape charts

  1. Right-click outside the body of the report, and select Report Properties.

  2. In Code, type the following code into the textbox.

    Private colorPalette As String() = {"Color1", "Color2", "Color3"}

    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


    You will need to replace the "Color1" strings with your own colors. You can use named colors, for example "Red", or you can use six-digit hexadecimal value that represent the color, such as "#FFFFFF" for black. If you have more than three colors defined, you will need to extend the array of colors so that the number of colors in the array matches the number of points in your Shape chart. You can add new colors to the array by specifying a comma-separated list of string values that contain named colors or hexadecimal representations of colors.

  3. Click OK.

  4. Right-click on the Shape chart and select Series Properties.

  5. In Fill, click the Expression (fx) button to edit the expression for the Color property.

  6. Type the following expression, where "MyCategoryField" is the field that is displayed in the category drop zone: