You need to sign in to do that
Don't have an account?

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;
}
}
}
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;
}
}
}
Hello, the below code will work.
After trying the above code and if it worked, please mark this answer correct. Thanks.