0

I have created a VF Pie chart which displays data of an object (Position__c). This object has a lookup to Contact. I want pie chart to be contact specific i.e whenever I select a Contact, data related to that specific contact should be visible on Pie chart. Attaching the code.

My Page:

<apex:pageBlock >
        <apex:pageblockSection title="Client">                
            <apex:selectList value="{!selectedName}" size="1">
            <apex:selectOptions value="{!ContactList}"/> 
             <apex:actionSupport event="onchange" action="{!ShowTransactions}" rerender="AccountSummarypageBlock,PositionPie"/>             
           </apex:selectList>
        </apex:pageblockSection> 
       </apex:pageBlock>  

<apex:outputPanel id="AccountSummarypageBlock" style="width:100%">                        
                    <apex:pageBlock id="AccountSummary" tabStyle="Position__c">
                        <apex:pageBlockSection title="Account Summary Details">
                        <apex:pageBlockSectionItem >
                        <apex:pageBlockTable value="{!conwrpList}" var="v" id="con">                            
                        <apex:column value="{!v.transRec.Category__c}" width="10%" />
                        <apex:column value="{!v.transRec.Quantity__c}" width="20%"/>
                        <apex:column value="{!v.transRec.CMP__c}" width="20%"/>
                        <apex:column value="{!v.transRec.Amount_New__c}"width="20%"/>
                        <apex:column value="{!v.transRec.Gain_Loss__c}" width="20%"/>                          
                        </apex:pageBlockTable>
                        </apex:pageBlockSectionItem>
                        </apex:pageBlockSection>
                        </apex:pageBlock>
                    </apex:outputPanel>                  
           <!-- New Pie Chart-->            
           <apex:outputPanel id="PositionPie" style="width:100%"> 
          <apex:pageBlock id="PositionData" title="Portfolio Mix">              
    <apex:chart height="250" width="350" data="{!PieData}" > 
        <apex:pieSeries tips="true" dataField="pdata" labelField="name"/> 
        <apex:legend position="right"/>
    </apex:chart>        
    </apex:pageBlock>
    </apex:outputPanel>

My Controller:

 Public List<Transaction__c > TransactionList{get;set;}  
Public List<Position__c> PositionList{get;set;} 
Public List<ContactWrapper> conwrpList{get;set;}
 Public String selectedName {get;set;}

 Public List<SelectOption> getContactList(){
List<SelectOption>ContactList = new List<SelectOption>();
    ContactList.add(new SelectOption('','------------select-----------'));
    List<Contact>conList = [select Id,Name, Group__c  from Contact where Group__c='Client'];
    for(Contact a:conList){
        ContactList.add(new SelectOption(a.id,a.name));
        System.debug('=====ContactList=====' +ContactList);
    }
    return ContactList;
}

Public PageReference ShowTransactions(){
    TransactionList = [select name, Account__c, Amount__c, Category__c,Amount_New__c, Client_ID__c, CMP__c, Gain_Loss__c, Order_Type__c, Product__c, Product_Code__c, Product__r.Price__c, Quantity__c, Transaction_Date__c, Yield__c from Transaction__c where Client_ID__c =:SelectedName];
 conwrpList = new List<ContactWrapper>();
    for(Transaction__c  w :TransactionList){
    conwrpList.add(new ContactWrapper(false,w));
  }
     return null;
 }

 public class ContactWrapper{
    public Boolean isSelected {get;set;}
    public Transaction__c  transRec {get;set;}
    public ContactWrapper(Boolean isSelected, Transaction__c  transRec){
    this.isSelected = isSelected;
    this.transRec = transRec;
    }
}   

  //Pie Chart

public List<PieWedgeData> getPieData() 
{  
    List<PieWedgeData> pdat = new List<PieWedgeData>();
    //List<Position__c> memb = new List<Position__c>();  
    List<Position__c> post = [SELECT ID, Product_New__c, Product__c, Quantity__c, Contact__c FROM Position__c];
    //String sql = 'SELECT Name, Product__c, Quantity__c FROM Position__c';
    //memb = Database.Query(sql);
    for(Position__c temp : post)
    {     
        //pdata.add(new PieWedgeData('State', 29));
        //System.debug('=====Product__c=====' +temp.Product__c);
        if(temp.Product_New__c !=null && temp.Quantity__c !=null)
        {
            pdat.add(new PieWedgeData(temp.Product_New__c, temp.Quantity__c));
        }
    }
    //pdata.add(new PieWedgeData('State', 29));
    //pdata.add(new PieWedgeData('Country', 25));
   // pdat.add(new PieWedgeData('Continent', 7));
    return pdat;  
} 

// Wrapper class  
public class PieWedgeData 
{  
    public String name { get; set; }  
    public Decimal pdata { get; set; }  

    public PieWedgeData(String name, Decimal pdata) 
    {  
        this.name = name;  
        this.pdata = pdata;  
    }  
}    
0

You code appears to set the Contact ID in a field called selectedName (that ought to be renamed).

So if Position__c.Contact__c is the Contact ID, this should filter your pie chart data correctly when you re-render PositionPie:

List<Position__c> post = [
        SELECT ID, Product_New__c, Product__c, Quantity__c, Contact__c
        FROM Position__c
        WHERE Contact__c = :selectedName
        ];
1
  • I did this earlier but it didn't worked at that time. However I modified the code again and added "WHERE" clause and this time it worked. Thanks alot.... Sep 5 '14 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.