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
Rishabh GoelRishabh Goel 

I need a Visualforce Page with Apex controller on Account. The vf Page should display a chart between annual revenue and account name with a filter as industry in picklist

<!-- VF Page -->
<apex:page controller="Graph5" sidebar="false">
     <apex:form >
        <apex:pageblock title="Turnover" >
        
        <apex:inputField value="{!myObject.Industry}">
            <apex:actionSupport event="onchange" reRender="graphBlock" />
        </apex:inputField>
            
        <apex:pageBlockSection collapsible="false" columns="1" id="graphBlock">
            <apex:chart height="350" width="450" data="{!GraphData}"> 
                <apex:axis type="Numeric" position="bottom" fields="amount" title="Amount"/>    
                <apex:axis type="Category" position="left" fields="name" title="Account"/>            
                <apex:barSeries orientation="horizontal" axis="left" yField="name" xField="amount" colorSet="lightBlue"/> 
            </apex:chart>
            
            <apex:chart height="400" width="600" data="{!GraphData}">
                <apex:pieSeries donut="50" labelField="name" dataField="amount" >
                    <apex:chartLabel display="middle" orientation="vertical" font="bold 0px Helvetica"/>
                </apex:pieSeries>
                <apex:legend position="right"/>
            </apex:chart>
        </apex:pageBlockSection>
           
        </apex:pageblock>
    </apex:form>      
</apex:page>

//Controller

public class Graph5
{
    public Account myObject {
        get {
            if (myObject == null)
            myObject = new Account();
            return myObject;
        }
        set;
    }
    List<Account> myObjectList = [select Name, AnnualRevenue from Account where Account.Industry= :myobject.Industry];    
    public List<GraphWedgeData> getGraphData() 
    {  
        List<GraphWedgeData> data = new List<GraphWedgeData>();
        for(Account a: myObjectList)
        {           
            data.add(new GraphWedgeData(a.Name,a.AnnualRevenue));
        }
        return data;  
    }    
    public class GraphWedgeData 
    {  
        public String name{get; set;} 
        public Decimal amount{get; set;}       
        public GraphWedgeData(String name, Decimal amount) 
        {  
            this.name = name;  
            this.amount= amount;  
        }  
    }      
}
Best Answer chosen by Rishabh Goel
Raj VakatiRaj Vakati
Here is the working copy of code
 
<apex:page controller="Graph5" sidebar="false">
    <apex:form >
        <apex:pageblock title="Turnover" >
            
            <apex:inputField value="{!myObject.Industry}">
                <apex:actionSupport event="onchange" reRender="graphBlock" />
            </apex:inputField>
            
            <apex:pageBlockSection collapsible="false" columns="1" id="graphBlock">
                <apex:chart height="350" width="450" data="{!GraphData}"> 
                    <apex:axis type="Numeric" position="bottom" fields="amount" title="Amount"/>    
                    <apex:axis type="Category" position="left" fields="name" title="Account"/>            
                    <apex:barSeries orientation="horizontal" axis="left" yField="name" xField="amount" colorSet="lightBlue"/> 
                </apex:chart>
                
                <apex:chart height="400" width="600" data="{!GraphData}">
                    <apex:pieSeries donut="50" labelField="name" dataField="amount" >
                        <apex:chartLabel display="middle" orientation="vertical" font="bold 0px Helvetica"/>
                    </apex:pieSeries>
                    <apex:legend position="right"/>
                </apex:chart>
            </apex:pageBlockSection>
            
        </apex:pageblock>
    </apex:form>      
</apex:page>
 
public class Graph5
{
    public Account myObject {
        get {
            if (myObject == null)
                myObject = new Account();
            return myObject;
        }
        set;
    }
    public List<GraphWedgeData> getGraphData() 
    {  
        List<Account> myObjectList = [select Name, AnnualRevenue from Account where Account.Industry= :myobject.Industry];    
        
        List<GraphWedgeData> data = new List<GraphWedgeData>();
        for(Account a: myObjectList)
        {           
            data.add(new GraphWedgeData(a.Name,a.AnnualRevenue));
        }
        return data;  
    }    
    public class GraphWedgeData 
    {  
        public String name{get; set;} 
        public Decimal amount{get; set;}       
        public GraphWedgeData(String name, Decimal amount) 
        {  
            this.name = name;  
            this.amount= amount;  
        }  
    }      
}

 

All Answers

Raj VakatiRaj Vakati
Here is the working copy of code
 
<apex:page controller="Graph5" sidebar="false">
    <apex:form >
        <apex:pageblock title="Turnover" >
            
            <apex:inputField value="{!myObject.Industry}">
                <apex:actionSupport event="onchange" reRender="graphBlock" />
            </apex:inputField>
            
            <apex:pageBlockSection collapsible="false" columns="1" id="graphBlock">
                <apex:chart height="350" width="450" data="{!GraphData}"> 
                    <apex:axis type="Numeric" position="bottom" fields="amount" title="Amount"/>    
                    <apex:axis type="Category" position="left" fields="name" title="Account"/>            
                    <apex:barSeries orientation="horizontal" axis="left" yField="name" xField="amount" colorSet="lightBlue"/> 
                </apex:chart>
                
                <apex:chart height="400" width="600" data="{!GraphData}">
                    <apex:pieSeries donut="50" labelField="name" dataField="amount" >
                        <apex:chartLabel display="middle" orientation="vertical" font="bold 0px Helvetica"/>
                    </apex:pieSeries>
                    <apex:legend position="right"/>
                </apex:chart>
            </apex:pageBlockSection>
            
        </apex:pageblock>
    </apex:form>      
</apex:page>
 
public class Graph5
{
    public Account myObject {
        get {
            if (myObject == null)
                myObject = new Account();
            return myObject;
        }
        set;
    }
    public List<GraphWedgeData> getGraphData() 
    {  
        List<Account> myObjectList = [select Name, AnnualRevenue from Account where Account.Industry= :myobject.Industry];    
        
        List<GraphWedgeData> data = new List<GraphWedgeData>();
        for(Account a: myObjectList)
        {           
            data.add(new GraphWedgeData(a.Name,a.AnnualRevenue));
        }
        return data;  
    }    
    public class GraphWedgeData 
    {  
        public String name{get; set;} 
        public Decimal amount{get; set;}       
        public GraphWedgeData(String name, Decimal amount) 
        {  
            this.name = name;  
            this.amount= amount;  
        }  
    }      
}

 
This was selected as the best answer
Raj VakatiRaj Vakati
Mark it as solved !
Rishabh GoelRishabh Goel
It worked ! Thanks for the changes.
Raj VakatiRaj Vakati
Mark it as a solved by choosing best answer