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
Piyush Sharma 6Piyush Sharma 6 

VF page not creating graph

Hello
I have created a vf page to display graph but it only displays page blocks. The graphs are not created.
I checked soql query in Graph controller is returning values.
Not sure where I am going wrong.

VF Page:
<apex:page controller="Graph" >
    <apex:pageblock title="Accounts and their Amount" >
        <apex:chart height="250" width="350" data="{!PieData}">
            <apex:pieSeries tips="true" dataField="data" labelField="name"/>
            <apex:legend position="bottom"/>
        </apex:chart>
    </apex:pageblock>                  
    <apex:pageblock title="Accounts and their Amount" >
        <apex:chart height="250" width="350" data="{!PieData}">
            <apex:axis type="Numeric" position="left" fields="data" title="Years of experience"/>    
            <apex:axis type="Category" position="bottom" fields="name" title="Account"/>            
            <apex:barSeries orientation="vertical" axis="left" xField="name" yField="data"/>
        </apex:chart>
    </apex:pageblock>    
</apex:page>

Controller:
public class Graph {
    public List<PieWedgeData> PieData{get;set;}
    public List<PieWedgeData> getPieData()
    {  
        List<PieWedgeData> data = new List<PieWedgeData>();
        List<Account> acc = new List<Account>();          
        String sql = 'SELECT Name, Total_Opportunity_Amount__c FROM Account where Total_Opportunity_Amount__c != null';
        acc = Database.Query(sql);
        System.debug('@@'+ acc);
        for(Account temp:acc)
        {           
            data.add(new PieWedgeData(temp.Name,temp.Total_Opportunity_Amount__c));
        }
        System.debug('@@ '+data);
        return data;
    }      
    // Wrapper class  
    public class PieWedgeData
    {  
        public String name { get; set; }  
        public Decimal data { get; set; }          
        public PieWedgeData(String name, Decimal data)
        {  
            this.name = name;  
            this.data = data;  
        }  
    }
}
 
Sunil MadanaSunil Madana
Hello, the below code will work.
<apex:page controller="Graph" >
    <apex:pageblock title="Accounts and their Amount" >
        <apex:chart height="250" width="350" data="{!PieData}">
            <apex:pieSeries tips="true" dataField="data" labelField="name"/>
            <apex:legend position="bottom"/>
        </apex:chart>
    </apex:pageblock>                  
    <apex:pageblock title="Accounts and their Amount" >
        <apex:chart height="250" width="350" data="{!PieData}">
            <apex:axis type="Numeric" position="left" fields="data" title="Years of experience"/>    
            <apex:axis type="Category" position="bottom" fields="name" title="Account"/>            
            <apex:barSeries orientation="vertical" axis="left" xField="name" yField="data"/>
        </apex:chart>
    </apex:pageblock>    
</apex:page>
public with sharing class Graph {
    public List<PieWedgeData> getPieData() {  
        List<PieWedgeData> data = new List<PieWedgeData>();
        List<Account> acc = new List<Account>();          
        String sql = 'SELECT Name, Total_Opportunity_Amount__c FROM Account where Total_Opportunity_Amount__c != null';
        acc = Database.Query(sql);
        System.debug('@@'+ acc);
        for(Account temp:acc)
        {
            System.debug('@@'+ temp);
            data.add(new PieWedgeData(temp.Name,temp.Total_Opportunity_Amount__c));
        }
        System.debug('@@ '+data);
        return data;
    }      
    // Wrapper class  
    public class PieWedgeData
    {  
        public String name { get; set; }  
        public Decimal data { get; set; }          
        public PieWedgeData(String name, Decimal data)
        {  
            this.name = name;  
            this.data = data;  
        }  
    }
}
After trying the above code and if it worked, please mark this answer correct. Thanks.