Chapter-13-Displaying Color in Data Bar Based on Condition

In “Chapter-12 Working with Data Bars in SSRS” we have created Data Bars in SSRS report. We are going to color these data bars based on certain conditions. For example, if value of “UnitsInStock” column is below 20 then display the bar in RED color else Green Color. Let us enter the below custom code to our report (refer Chapter-7-Working with Expression and Custom Code).

Download Full Tutorial for Chapter-13-Displaying-Colour-in-Data-Bar-Based-on-Condition



Download Source Code for Chapter-13-Displaying Colour in Data Bar Based on Condition_files

Step-1: Right click  below the report area and choose Report Properties to open Report Properties window.

open Report Properties window
open Report Properties window

Step-2: Paste the custom code to the “Custom Code” text area as shown in the image.

The Custom code will be.
Public Shared Function BarColor(ByVal StockUnit As Integer) As String
BarColor= “Red”
If StockUnit > 20 Then
BarColor= “Green”
End IF
End Function

Paste the custom code to the “Custom Code” text area
Paste the custom code to the “Custom Code” text area




Step-3: Double Click on Data Bar a “Chart Data” popup will appear and then right-click on the bar and select “Series Properties..” as shown in the image.

select Series Properties
Select Series Properties

In the Series Properties window, select the Fill tab and click the Expression button (fx) as shown in the image.

Click the Expression button (fx)
Click the Expression button (fx)

And in the expression editor enter the below expression as shown in the image and click ok.

=Code.BarColor(Fields!UnitsInStock.Value)

Enter the expression in Expression Window
Enter the expression in Expression Window

Now run the report and see the view. This completes the “Chapter-13-Displaying Colour in Data Bar Based on Condition”.

Preview of the Data Bars Report in SSRS based on Certain Conditions
Preview of the Data Bars Report in SSRS based on Certain Conditions




Chapter-1: Creating a basic Tabular SSRS Report using Report Wizard
Chapter-2 : Report Deployment on SQL Server 2012 Reporting Server
Chapter-3:Opening/Calling the deployed SQL Server Reporting Server report from Asp.net
Chapter-4 Creating SSRS Matrix Report / Cross Tab Report
Chapter-5 Creating a Sub Report in SSRS
Chapter-6: Creating a Drill Down Report in SSRS
Chapter-7: Working with expressions and custom code in SSRS
Chapter-8-SSRS (Reporting Services) Working with Calculated fields
Chapter-9-Sorting of Column and Custom Paging in SSRS
Chapter-10 : Creating and Deploying Web Services for SSRS
Chapter-11 : Creating SSRS Report by consuming Web Service Data Source
Chapter-12 : Working with Data Bars in SSRS

Leave a Reply

Your email address will not be published. Required fields are marked *

*

sixteen − twelve =