Search code examples
reporting-servicescolorschartsscalebar-chart

SSRS - bar chart - bar color scale depending on value


I've created a bar chart that has 1 data series and about 8 bars with values in range 0-100%. A while ago I've found a tutorial on how to make diffrent colors for columns in the same data series, and tried to modify it to suit my current needs, but I'm doing something wrong.

Diffrent colors in the same data series works like that:

I edit the report code to add the following function:

Private colorPalette As String() = {"Green", "Blue", "Red", "Orange", "Aqua", "Teal", "Gold", "RoyalBlue", "#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

Now I have publicly accessible function GetColor which I use in a formula for data series color on the chart (series properties, 'Fill' tab):

=Code.GetColor(Fields!proc_choroby.Value)

I've tried to modify the original function to return colors depending on series value. I've written this code but it's apparently wrong:

Public Function GetColor(ByVal value As Single) As String
    Dim color As String
    If value < 0.4 Then
    color = "FFFFCC"
    ElseIf value > 0.4 And value < 0.6 Then
    color = "FFFF00"
    ElseIf value > 0.6 And value < 0.7 Then
    color = "FFCC00"
    ElseIf value > 0.7 And value < 0.8 Then
    color = "FF9900"
    ElseIf value > 0.8 And value < 0.9 Then
    color = "993300"
    Else: color = "800000"
    End If
    Return color
End Function

Solution

  • I've just found the error, returned color values are missing '#' at the beginning. The rest works exactly as it should.

    My problem has been solved, but I'm going to post the question anyway in case someone wants to use this in the future and I didn't find anything in google on the subject.