While we design SSRS chart, we have to use available colors from SSRS Color pallette or color templates by selecting them from color, background color, etc. Instead we can apply our own defined colors to our chart by following below steps:
Step 1: Create new SSRS report.
Step 2: Go to Report properties of the SSRS report. Open Code section and copy-paste the below code in the Code area:
Private colorPalette As String() = { "Blue", "Red", "Teal", "Gold", "Green","#A59D93", "#B8341B", "#352F26", "#F1E7D6", "#E16C56", "#CFBA9B"}
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
Step 3: Now create a chart (e.g., pie chart); Open Series properties, in Fill expression copy-paste below command:
=code.GetColor(Fields!SalesMonth.Value)
Step 4 (Option): You can use this color in your grid report as a background, by copy-paste the below code in Columns Background properties:
=code.GetColor(Fields!SalesMonth.Value)
The output will be simillar to one below:
Step 1: Create new SSRS report.
Step 2: Go to Report properties of the SSRS report. Open Code section and copy-paste the below code in the Code area:
Private colorPalette As String() = { "Blue", "Red", "Teal", "Gold", "Green","#A59D93", "#B8341B", "#352F26", "#F1E7D6", "#E16C56", "#CFBA9B"}
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
Step 3: Now create a chart (e.g., pie chart); Open Series properties, in Fill expression copy-paste below command:
=code.GetColor(Fields!SalesMonth.Value)
Step 4 (Option): You can use this color in your grid report as a background, by copy-paste the below code in Columns Background properties:
=code.GetColor(Fields!SalesMonth.Value)
The output will be simillar to one below:
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.