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
krishna guptakrishna gupta 

I am executing the code provided in visualforce page book, but i am not able to get the expected output

Apex Class:
-----------------
public class OppsController {

    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null){
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                    [SELECT name, type, amount, closedate FROM Opportunity]));
                setCon.setPageSize(5);
            }
            return setCon;
        }
        set;
    }
    
    public List<Opportunity> getOpportunities(){
        return (List<Opportunity>) setCon.getRecords();
    }
}

Visualforce Page:
-------------------------
<apex:page controller="OppsController" >
    <apex:chart data="{!Opportunities}" height="400" width="600">
        <apex:axis type="Category" position="left" fields="name" title="Opportunities" />
        <apex:axis type="Numeric" position="bottom" fields="amount" title="Amount" />
        <apex:barSeries orientation="horizontal" axis="bottom" xField="name" yField="amount" />
    </apex:chart>
    <apex:dataTable value="{!Opportunities}" var="opp" >
        <apex:column headerValue="Opportunity" value="{!opp.name}" />
        <apex:column headerValue="Amount" value="{!opp.amount}" />
    </apex:dataTable>
</apex:page>
Best Answer chosen by krishna gupta
karthikeyan perumalkarthikeyan perumal
Hello, 

i think you are trying to diplay a bar chart above the table... Change the code like below. 

Class
 
public   class OppsController {
public List<oppWedgeData> getOppData()
    { 
        List<oppWedgeData> data = new List<oppWedgeData>();
        List<Opportunity> opp= new List<Opportunity>(); 
       
        String sql = 'SELECT Name, Amount FROM Opportunity limit 10';
        opp= Database.Query(sql);
        for(Opportunity temp:opp)
        {          
            data.add(new oppWedgeData(temp.Name,temp.Amount));
        }
        return data; 
    } 
   
    
    public class oppWedgeData
    { 
        public String name { get; set; } 
        public Decimal data { get; set; } 
       
        public oppWedgeData(String name, Decimal data)
        { 
            this.name = name; 
            this.data = data; 
        } 
    }  
}

VF page
<apex:page controller="OppsController " >
                     
    <apex:pageblock title="Opportunity" >
        <apex:chart height="300" width="1000" data="{!OppData}">
            <apex:axis type="Numeric" position="left" fields="data" title="Amount"/>   
            <apex:axis type="Category" position="bottom" fields="name" title="Opportunity Name"/>           
            <apex:barSeries orientation="vertical" axis="left" xField="name" yField="data"/>
        </apex:chart>
    </apex:pageblock> 
    
    <apex:dataTable value="{!OppData}" var="opp" >
        <apex:column headerValue="Opportunity" value="{!opp.name}" />
        <apex:column headerValue="Amount" value="{!opp.data}" />
    </apex:dataTable>          
</apex:page>

Out put: 

User-added image

Hope this will help you, 

Mark best ANSWER if its work for you.. 

Thanks
karthik
 

All Answers

Ashutosh AwasthiAshutosh Awasthi
Hi krishna,

On running the code provided by you I got the following output

User-added image

Can you please let me know wht is your desired output so I can help you to achieve the same.
Amit GhadageAmit Ghadage
Hi Krishna modify your vaf page and controller as below

Controller
public class OppsController {
    public ApexPages.StandardSetController setCon{get;set;}
    public OppsController(ApexPages.StandardController controller) {
        if(setCon == null){
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                    [SELECT name, type, amount, closedate FROM Opportunity]));
                setCon.setPageSize(5);
                }
    }

    public List<Opportunity> getOpportunities(){
        return (List<Opportunity>) setCon.getRecords();
    }
    }
Vf page :
<apex:page standardController="Opportunity" extensions="OppsController" >
    <apex:chart data="{!Opportunities}" height="400" width="600">
        <apex:axis type="Category" position="left" fields="name" title="Opportunities" />
        <apex:axis type="Numeric" position="bottom" fields="amount" title="Amount" />
        <apex:barSeries orientation="horizontal" axis="bottom" xField="name" yField="amount" />
    </apex:chart>
   <apex:form >
    <apex:pageBlock >
         <apex:pageBlockTable value="{!Opportunities}" var="opp" >
        <apex:column headerValue="Opportunity" value="{!opp.name}" />
        <apex:column headerValue="Amount" value="{!opp.amount}" />
    </apex:pageBlockTable> 
     <apex:commandButton value="Previous" action="{!setCon.previous}" disabled="{!!setCon.hasprevious}" />
    <apex:commandButton value="Next" action="{!setCon.next}" disabled="{!!setCon.hasNext}" />
   
    
    </apex:pageBlock>
   </apex:form>
</apex:page>

 
karthikeyan perumalkarthikeyan perumal
Hello, 

i think you are trying to diplay a bar chart above the table... Change the code like below. 

Class
 
public   class OppsController {
public List<oppWedgeData> getOppData()
    { 
        List<oppWedgeData> data = new List<oppWedgeData>();
        List<Opportunity> opp= new List<Opportunity>(); 
       
        String sql = 'SELECT Name, Amount FROM Opportunity limit 10';
        opp= Database.Query(sql);
        for(Opportunity temp:opp)
        {          
            data.add(new oppWedgeData(temp.Name,temp.Amount));
        }
        return data; 
    } 
   
    
    public class oppWedgeData
    { 
        public String name { get; set; } 
        public Decimal data { get; set; } 
       
        public oppWedgeData(String name, Decimal data)
        { 
            this.name = name; 
            this.data = data; 
        } 
    }  
}

VF page
<apex:page controller="OppsController " >
                     
    <apex:pageblock title="Opportunity" >
        <apex:chart height="300" width="1000" data="{!OppData}">
            <apex:axis type="Numeric" position="left" fields="data" title="Amount"/>   
            <apex:axis type="Category" position="bottom" fields="name" title="Opportunity Name"/>           
            <apex:barSeries orientation="vertical" axis="left" xField="name" yField="data"/>
        </apex:chart>
    </apex:pageblock> 
    
    <apex:dataTable value="{!OppData}" var="opp" >
        <apex:column headerValue="Opportunity" value="{!opp.name}" />
        <apex:column headerValue="Amount" value="{!opp.data}" />
    </apex:dataTable>          
</apex:page>

Out put: 

User-added image

Hope this will help you, 

Mark best ANSWER if its work for you.. 

Thanks
karthik
 
This was selected as the best answer