Monday, 25 January 2010

Custom Colours in Pie Charts


I created a number of pie charts which compared the data for a number of clients in different years. As some of the clients did not have any data in some of the years the default colours were mixed up.

To remedy this you can use the code below to specify the colours you want.

The code below is inserted in the report properties window under the code tab.





Private colorPalette As String() = { "purple","blue","darkgreen","lightgreen","pink","teal","yellow","gray","black"}
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 can choose the colours you want in between the brackets the order is from let to right.
{ "purple","blue","darkgreen","lightgreen","pink","teal","yellow","gray","black"}


When you have entered the code you can use this in your pie chart.
Edit the value in the data tab of your chart properties then edit the value, appearance,series style, fill, color and then click on the expression box and enter the following expression
=Code.GetColor(Fields!.YOURFIELD.Value)

Page Layout in Landscape Mode


I have quite a few requests to create reports in landscape format.
In the report properties window change the page width to 29.6cm
and the page height to 21cm and set the margins to 1cm.

Alternating colours

How to use alternating colours in a table created in ssrs


Highlight the row or the cell in the details section of your report and then in the properties window in background (under Appearance). Select the Expression and in the Expression box
type in the following code.


=iif(RowNumber(Nothing) Mod 2, "silver", "White")
=iif(RowNumber(Nothing) Mod 2, "White","#fff4cb")
=iif(RowNumber(Nothing) Mod 2, "White","aliceblue")

You can use custom clours as well.

To use the custom colours create a custom colour in the expression window then double click the colour and the code will appear in the text box.

For alternate colours in a matrix row group use :

=IIf( RunningValue (Fields!FIELDNAME.Value, CountDistinct, Nothing) MOD 2, "Transparent", "aliceblue")

Reporting Services Tips n Tricks

Hi, I have started this blog so I could keep all my reporting services tips in one place.

Keep SSRS (SSRS2016) report manager awake

When running a report for the first time in report manager it takes a while to run, after this initial run reports run fine.  There are a ...