SAP Knowledge Base Article - Public

2091102 - Conditionally color bars on a chart in Crystal Reports based on a value not used in the chart

Symptom

  • Color bars on a chart based on specific criterias.
  • How to conditionnaly format the color of bars on a chart based on a non-summary value in Crystal Reports?

Environment

  • Crystal Reports 2008
  • SAP Crystal Reports 2011
  • SAP Crystal Reports 2013

Resolution

  • In Crystal Reports, it is possible to conditionally format the colors of bars in a Bar Chart using the Chart Color Highlight option in the Chart Expert , but it is limited to the summary and database fiels used on the chart. How to conditionnaly format the color of bars on a chart based on a non-summary value?
          
  • In order to conditionnaly format the bar color based on a value of a database field not in the chart, use a Stacked Bar Chart and Formulas to acheive the desired result. To do so, follow the general steps below:

    1. Create one formula for each color to display for the bar on the chart.
      Each formula will output the chart summary value only if the conditions are met.
        
      For example: If the chart requirement is to display the bar color of the Sales Amount in: Gray, Gold or Blue,
      depending if the Customer belong to a specific category, then 3 formulas needs to be created, one for each color.
      The formula will look like:
        
      If  {Customer.Category} = "Owner" Then {Sales Amount}  Else 0  
            
    2. Insert a Stacked Bar Chart on the report, and insert each of the formula created under the "Show Values" of the chart.
        
      Color - 01.png
                 
            
    3. In the Design view of the report, format each stack of the bar chart with the desired color.
      To do so, right click on the first stack of the bar, and select "Format Series Riser", and change the color.

      In this example, the first one will be colored in gray, the second gold, and the third one in blue.
       
      Color - 02.png   
       

    4. After following the above steps, the chart will then display the colored based on the conditions set in the formula.
      For a sample report that demonstrate this technique, click here.
        
      Color - 03.png

Keywords

CR, chart, grap, conditions, color, colour, formatting , KBA , BI-RA-CR , Crystal Reports designer or Business View Manager , How To

Product

Crystal Reports 2008 V0 ; Crystal Reports 2008 V1 ; SAP Crystal Reports 2011 ; SAP Crystal Reports 2013

Attachments

Bar Chart - Sample Report.rpt