1551236 - How to format the chart X axis to display no decimals in Crystal Reports?

SAP Knowledge Base Article - Public

1551236 - How to format the chart X axis to display no decimals in Crystal Reports?

Symptom

  • Decimals shows on the chart X axis.
  • How to remove the zeros decimals for the numeric values of the chart x-axis?
  • X axis of a graph show number fields in the format 2 015.00, how to display it without decimals like: 2015?
  • On one computer, the chart displays no decimals for the X axis of the chart, but displays decimals on a different computer.
  • How to format numeric values of the X axis of a line or bar chart to show no decimals in Crystal Reports?

Environment

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

Reproducing the Issue

  1. In Crystal Reports designer, create a report off any data source.
  2. Insert a line or bar chart on the report, with a numeric value for the X axis, like years.
  3. Notice the x axis displays the numbers with decimals. In this example, it show years with decimals, when it should not displays decimals for years.
         
    Chart - Decimals - 02.png
      
     

Cause

  • Chart numeric values are formatted based on the regional setting of the computer where the report is executed.
             
  • For examples:
    - If the local computer have the regional settings for the numeric values to shows 2 decimals, then the numeric values on the chart will show 2 decimals in Crystal Reports.
    - If the same report is open on a different computer, where the regional setting is set to displays no decimals for the numeric values, then no decimals will displays on the chart.

Resolution

  • To ensure there is no decimals displayed on the x axis of the chart, convert the numeric values to text, and use the converted value for the x axis on the chart. To do so:
      
    1. In Crystal Reports deisgner, open the report on which you have the chart.
    2. Create a formula that converts the numeric value used on the X axis of the chart to a text without decimals. The formula will look like:
        
          ToText({MyTable.Year},0,"")
         
    3. Edit the chart, and replace the database field used for the X axis of the chart by the formula.
      3.1  Right click on the chart, and select "Chart Expert"
      3.2  In the "Chart Expert" window, under the tab "Data", remove the field used under "On Change of", and replace it with the formula created in step 2.
        
              Chart - Decimals - 01.png
            

      3.3  Click "OK" to accept the change.
       
      Now, the chart will display the X axis numeric value with no decimals. 
        
             Chart - Decimals - 03.png
         
          
         
  • Sample report demonstrating this solution:  Chart X Axis Without Decimals.rpt
           
  • Important Note:
         
    When using this solution, ensure the numeric values always have the same number of characters, otherwise the X axis sort will be incorrect, as it is sorted according to the string and not sorted by the number.

Keywords

X-axis,Crystal Reports,charts,remove decimal places , KBA , BI-RA-CR , Crystal Reports designer or BusinessViews Manager , Problem

Product

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

Attachments

Chart X Axis Without Decimals.rpt