function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anuj Joshi 42Anuj Joshi 42 

Values to be shown as per user locale/country in visualforce bar chart

Hi All,

I have a custom bar chart written in VF page where we are dsipalying records based on controller. Currently we are displayng the values in generic way. But we want to display values differently based on user locale/country. For example the value shown to Indian user will be 1,00,000 but the same value shown to US user will be in the format 100,000. Kindly provide me solution.

Thanks,
Anuj
Manish  ChoudhariManish Choudhari
Hi Anuj,

Did you try UserInfo class in your controller? You can get running user's locale using this class. Checkout this link: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_userinfo.htm

getLocale() -Returns the context user's locale.
String result = UserInfo.getLocale();
System.assertEquals('en_US', result);​

Now you can define your data/logic in controller to return the data to visualforce based on running user's locale.

Similarly, we have $User global variable in Visualforce to get running user's properties. https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_variables_global_user.htm

Let me know if this helps.

**Please mark this as best answer if this answers your query.**

Thanks,
Manish Choudhari
14x Certified Salesforce Architect
Certification link:
http://certification.salesforce.com/certification-detail-print?conId=003G000002gRrrEIAS​
My Blog: http://sfdcfacts.com/
Youtube Channel: https://www.youtube.com/SFDCFacts
LinkedIn: https://www.linkedin.com/in/manish-choudhary/
Trailhead: https://trailhead.salesforce.com/en/me/manish-choudhari
Twitter: https://mobile.twitter.com/manish_sfdc
Anuj Joshi 42Anuj Joshi 42
Hi Manish,

11321 in first bar value appears as 11,321 USD in USA user In Europe it appears differently in Europe like 142.44 means the values should come based on their locale.

User-added image

The code is below

VF Page:
 
<apex:page standardController="Account" tabStyle="Account" extensions="RevenueSummaryController" title="RevenueSummary"  showHeader="false"  sidebar="false" readonly="true" >
    

     <apex:panelGrid columns="4"  >
        <apex:pageblock id="blockA">
            <apex:chart data="{!data}" height="270" width="230" colorSet="#006699" >
                <apex:legend position="bottom"/>
                <apex:axis type="Numeric" position="left" title="Equip & Accs({!usersCurrency })" grid="true"
                    fields="data1,data2,data3" dashSize="2" >
                    <apex:chartLabel />
                </apex:axis>
                <apex:axis type="Category" position="bottom" fields="name" >
                    <apex:chartLabel rotate="100"/>
                </apex:axis>
                <apex:barSeries title="Equip & Accs" orientation="vertical" axis="left"
                        xField="name" yField="data1" tips="true" stacked="true" >
                <apex:chartTips height="20" width="120"/>
                <apex:chartLabel field="data1" display="outside" orientation="horizontal" font="22px" />
                </apex:barSeries>
                
            </apex:chart>
        </apex:pageblock>
        
        <apex:pageblock id="blockB">
             <apex:chart data="{!data2}"  height="270" width="230"  colorSet="#006699" >
                <apex:legend position="bottom"/>
                <apex:axis type="Numeric" position="left" title="Supplies({!usersCurrency })" grid="true"
                    fields="data1,data2,data3" dashSize="2">
                    <apex:chartLabel />
                </apex:axis>
                <apex:axis type="Category" position="bottom" fields="name" >
                    <apex:chartLabel rotate="100"/>
                </apex:axis>
                <apex:barSeries title="Supplies" orientation="vertical" axis="left"
                        xField="name" yField="data1" tips="true" stacked="true" >
                <apex:chartTips height="20" width="120"/>
                <apex:chartLabel field="data1" display="outside" orientation="horizontal" font="12px"/>
                </apex:barSeries>
            </apex:chart>
        </apex:pageblock>
        
        <apex:pageblock id="blockC">
              <apex:chart data="{!data1}"  height="270" width="230" colorSet="#006699"  >
                <apex:legend position="bottom"/>
                <apex:axis type="Numeric" position="left" title="Service({!usersCurrency })" grid="true"
                    fields="data1,data2,data3" dashSize="2">
                    <apex:chartLabel />
                </apex:axis>
                <apex:axis type="Category" position="bottom" fields="name" >
                    <apex:chartLabel rotate="100"/>
                </apex:axis>
                <apex:barSeries title="Service" orientation="vertical" axis="left"
                        xField="name" yField="data1" tips="true" stacked="true" >
                <apex:chartTips height="20" width="120"/>
                <apex:chartLabel field="data1" display="outside" orientation="horizontal" font="12px"/>
                </apex:barSeries>
            </apex:chart>
        </apex:pageblock>
        
        <apex:pageblock id="blockD">
              <apex:chart data="{!data3}"  height="270" width="230" colorSet="#006699"  >
                <apex:legend position="bottom"/>
                <apex:axis type="Numeric" position="left" title="Parts({!usersCurrency })" grid="true"
                    fields="data1,data2,data3" dashSize="2">
                    <apex:chartLabel />
                </apex:axis>
                <apex:axis type="Category" position="bottom" fields="name" >
                    <apex:chartLabel rotate="100"/>
                </apex:axis>
                <apex:barSeries title="Parts" orientation="vertical" axis="left"
                        xField="name" yField="data1" tips="true" stacked="true" >
                <apex:chartTips height="20" width="120"/>
                <apex:chartLabel field="data1" display="outside" orientation="horizontal" font="12px"/>
                </apex:barSeries>
            </apex:chart>
        </apex:pageblock>
        
    </apex:panelGrid>
</apex:page>

Controller:
 
global  class RevenueSummaryController{

    public Account acc {get;set;}
    public String usersCurrency {get;set;}
    public String userslocale{get;set;}
    
    public RevenueSummaryController(ApexPages.StandardController controller) {
    
        usersCurrency = Userinfo.getDefaultCurrency();
        userslocale =Userinfo.getLocale();
        acc= (Account)controller.getRecord();
        accList =[SELECT id,DW_Revenue_Equipment_CY_USD__c,DW_Revenue_Equipment_PY_USD__c,DW_Revenue_Equipment_CY_2_USD__c,
        DW_Revenue_Accessories_CY_USD__c,DW_Revenue_Accessories_PY_USD__c,DW_Revenue_Accessories_CY_2_USD__c,
        DW_Revenue_Supplies_PY_USD__c,DW_Revenue_Supplies_CY_USD__c,DW_Revenue_Supplies_CY_2_USD__c,
        DW_Revenue_Parts_CY_2_USD__c,DW_Revenue_Parts_CY_USD__c,DW_Revenue_Parts_PY_USD__c,
        DW_Revenue_Service_CY_2_USD__c,DW_Revenue_Service_CY_USD__c,DW_Revenue_Service_PY_USD__c from Account where id= : acc.Id ];
    }


    public static List<Account> accList {get;set;}
   
    // Return a list of data points for a chart
    public List<Data> getData() {
        return RevenueSummaryController.getChartData();
    }
    public List<Data> getData1() {
        return RevenueSummaryController.getChartData1();
    }
    public List<Data> getData2() {
        return RevenueSummaryController.getChartData2();
    }
    public List<Data> getData3() {
        return RevenueSummaryController.getChartData3();
    }
    
    // Make the chart data available via JavaScript remoting
    @RemoteAction
    global static List<Data> getRemoteData() {
        return RevenueSummaryController.getChartData();
    }
     @RemoteAction
    global static List<Data> getRemoteData1() {
        return RevenueSummaryController.getChartData1();
    }
     @RemoteAction
    global static List<Data> getRemoteData2() {
        return RevenueSummaryController.getChartData2();
    }
     @RemoteAction
    global static List<Data> getRemoteData3() {
        return RevenueSummaryController.getChartData3();
    }
    
    // The actual chart data; needs to be static to be
    // called by a @RemoteAction method
    global static List<Data> getChartData() {
        List<Data> data = new List<Data>();
        if(accList.size() >0){
            
            try{
                if(accList[0].DW_Revenue_Equipment_CY_2_USD__c != null && accList[0].DW_Revenue_Accessories_CY_2_USD__c != null )
                data.add(new Data('CY-2', Integer.valueOf( accList[0].DW_Revenue_Equipment_CY_2_USD__c)+Integer.valueOf( accList[0].DW_Revenue_Accessories_CY_2_USD__c), 0, 0,0));
                 
                else if(accList[0].DW_Revenue_Equipment_CY_2_USD__c != null && accList[0].DW_Revenue_Accessories_CY_2_USD__c == null )
                data.add(new Data('CY-2', Integer.valueOf( accList[0].DW_Revenue_Equipment_CY_2_USD__c), 0, 0,0));
                
                else if(accList[0].DW_Revenue_Equipment_CY_2_USD__c == null && accList[0].DW_Revenue_Accessories_CY_2_USD__c != null )
                data.add(new Data('CY-2', Integer.valueOf( accList[0].DW_Revenue_Accessories_CY_2_USD__c), 0, 0,0));  
                
                else
                data.add(new Data('CY-2',  0, 0, 0,0));   
                                
                if(accList[0].DW_Revenue_Equipment_PY_USD__c  != null && accList[0].DW_Revenue_Accessories_PY_USD__c != null)
                data.add(new Data('CY-1',  Integer.valueOf( accList[0].DW_Revenue_Equipment_PY_USD__c )+Integer.valueOf( accList[0].DW_Revenue_Accessories_PY_USD__c), 0, 0,0));                
                
                else if(accList[0].DW_Revenue_Equipment_PY_USD__c  != null && accList[0].DW_Revenue_Accessories_PY_USD__c == null)
                data.add(new Data('CY-1',  Integer.valueOf( accList[0].DW_Revenue_Equipment_PY_USD__c ), 0, 0,0));                
                
                else if(accList[0].DW_Revenue_Equipment_PY_USD__c  == null && accList[0].DW_Revenue_Accessories_PY_USD__c != null)
                data.add(new Data('CY-1',  Integer.valueOf( accList[0].DW_Revenue_Accessories_PY_USD__c), 0, 0,0));
                
                else
                data.add(new Data('CY-1',  0, 0, 0,0));
                
                if(accList[0].DW_Revenue_Equipment_CY_USD__c  != null && accList[0].DW_Revenue_Accessories_CY_USD__c != null )
                data.add(new Data('CY',  Integer.valueOf( accList[0].DW_Revenue_Equipment_CY_USD__c )+Integer.valueOf( accList[0].DW_Revenue_Accessories_CY_USD__c) , 0, 0,0)); 
                               
                else if(accList[0].DW_Revenue_Equipment_CY_USD__c  != null && accList[0].DW_Revenue_Accessories_CY_USD__c == null )
                data.add(new Data('CY',  Integer.valueOf( accList[0].DW_Revenue_Equipment_CY_USD__c ), 0, 0,0));                
                
                else if(accList[0].DW_Revenue_Equipment_CY_USD__c  == null && accList[0].DW_Revenue_Accessories_CY_USD__c != null )
                data.add(new Data('CY', Integer.valueOf( accList[0].DW_Revenue_Accessories_CY_USD__c) , 0, 0,0));
                
                else
                data.add(new Data('CY',  0, 0, 0,0));
                
                /*if(accList[0].DW_Revenue_Equipment_CY_2_USD__c == null && accList[0].DW_Revenue_Accessories_CY_2_USD__c == null && accList[0].DW_Revenue_Equipment_PY_USD__c == null && accList[0].DW_Revenue_Accessories_PY_USD__c== null && accList[0].DW_Revenue_Equipment_CY_USD__c == null && accList[0].DW_Revenue_Accessories_CY_USD__c  == null ){
                    data.add(new Data('CY-2',  0, 0, 0,0));
                    data.add(new Data('CY-1',  0, 0, 0,0));
                    data.add(new Data('CY',  0, 0, 0,0));
                }*/
            }
            Catch(Exception e){
                System.debug('e.getMessage()******' +e.getMessage());
            }
        }
         
        return data;
    }
    global static List<Data> getChartData1() {
        List<Data> data = new List<Data>();
        try{
               
            if(accList[0].DW_Revenue_Service_CY_2_USD__c!= null)
            data.add(new Data('CY-2', Integer.valueOf( accList[0].DW_Revenue_Service_CY_2_USD__c), 0, 0,0));
            else
            data.add(new Data('CY-2',  0, 0, 0,0));
                
            if(accList[0].DW_Revenue_Service_PY_USD__c!= null)
            data.add(new Data('CY-1',  Integer.valueOf( accList[0].DW_Revenue_Service_PY_USD__c), 0, 0,0));
            else
            data.add(new Data('CY-1',  0, 0, 0,0));
                
            if(accList[0].DW_Revenue_Service_CY_USD__c!= null)
            data.add(new Data('CY',  Integer.valueOf( accList[0].DW_Revenue_Service_CY_USD__c) , 0, 0,0));
            else
            data.add(new Data('CY',  0, 0, 0,0));
            
        }
        Catch(Exception e){
            System.debug('e.getMessage()******' +e.getMessage());
        }
        return data;
    }
    
    global static List<Data> getChartData2() {
        
        List<Data> data = new List<Data>();
        try{
                
            if(accList[0].DW_Revenue_Supplies_CY_2_USD__c != null)
            data.add(new Data('CY-2', Integer.valueOf( accList[0].DW_Revenue_Supplies_CY_2_USD__c), 0, 0,0));
            else
            data.add(new Data('CY-2',  0, 0, 0,0));
                
            if(accList[0].DW_Revenue_Supplies_PY_USD__c != null)
            data.add(new Data('CY-1',  Integer.valueOf( accList[0].DW_Revenue_Supplies_PY_USD__c), 0, 0,0));
            else
            data.add(new Data('CY-1',  0, 0, 0,0));
                
            if(accList[0].DW_Revenue_Supplies_CY_USD__c != null)
            data.add(new Data('CY',  Integer.valueOf( accList[0].DW_Revenue_Supplies_CY_USD__c) , 0, 0,0));
            else
            data.add(new Data('CY',  0, 0, 0,0));
        }
        Catch(Exception e){
            System.debug('e.getMessage()******' +e.getMessage());
        }
        return data;
    }
    
    global static List<Data> getChartData3() {
        List<Data> data = new List<Data>();
        try{
            if(accList[0].DW_Revenue_Parts_CY_2_USD__c != null)
            data.add(new Data('CY-2', Integer.valueOf( accList[0].DW_Revenue_Parts_CY_2_USD__c), 0, 0,0));
            else
            data.add(new Data('CY-2',  0, 0, 0,0));
            
            if(accList[0].DW_Revenue_Parts_PY_USD__c != null)
            data.add(new Data('CY-1',  Integer.valueOf( accList[0].DW_Revenue_Parts_PY_USD__c), 0, 0,0));
            else
            data.add(new Data('CY-1',  0, 0, 0,0));
                
            if(accList[0].DW_Revenue_Parts_CY_USD__c != null)
            data.add(new Data('CY',  Integer.valueOf( accList[0].DW_Revenue_Parts_CY_USD__c) , 0, 0,0));
            else
            data.add(new Data('CY',  0, 0, 0,0));
            
        }
        Catch(Exception e){
            System.debug('e.getMessage()******' +e.getMessage());
        }
        return data;
    }
    
    // Wrapper class
    global  class Data {
        public String name { get; set; }
        public Integer data1 { get; set; }
        public Integer data2 { get; set; }
        public Integer data3 { get; set; }
        public Integer data4 { get; set; }
        
        public Data(String name, Integer data1, Integer data2, Integer data3,Integer data4) {
            this.name = name;
            this.data1 = data1;
            this.data2 = data2;
            this.data3 = data3;
            this.data4 = data4;
        }
    }
}