I have created a VF chart to display a Line chart with 2 data series. Now I have written 2 differnt methods in order to fetch the data from 2 different unrelated objects. In order to call these 2 methods in data attribute of , I have created page reference method and called these 2 methods. Now when Im trying to call this page reference method in my VF page, its giving an error Unknown property 'MyController.mastermethod
. Please suggest.
Controller-
public PageReference masterMethod() {
getLineData();
getLineData1();
return null;
}
//Method 1
public List<LineChartData> getLineData()
{
List<LineChartData> ldata = new List<LineChartData>();
List<Profile__c> pv = new List<Profile__c>();
String sql = 'SELECT Name, Profile_Value__c, Date__c FROM Profile__c';
pv = Database.Query(sql);
for(Profile__c temp: pv)
{
if(temp.Profile_Value__c !=null && temp.Date__c !=null)
{
ldata.add(new LineChartData(temp.Date__c, temp.Profile_Value__c));
}
}
return ldata;
}
// Wrapper class
public class LineChartData
{
public Date Date1 { get; set; }
public Decimal Profile { get; set; }
public LineChartData(Date Date1, Decimal Profile)
{
this.Date1 = Date1;
this.Profile = Profile;
}
}
//Method 2
public List<LineChartData1> getLineData1()
{
List<LineChartData1> ldata1 = new List<LineChartData1>();
List<Contact> cont1 = new List<Contact>();
String sql = 'SELECT id, Name, Date__c, Market_Value__c FROM Contact WHERE id= :selectedName';
cont1 = Database.Query(sql);
for(Contact temp: cont1)
{
if(temp.Market_Value__c !=null && temp.Date__c !=null)
{
ldata1.add(new LineChartData1(temp.Date__c, temp.Market_Value__c));
}
}
return ldata1;
}
// Wrapper class
public class LineChartData1
{
public Date Date2 { get; set; }
public Decimal MarketValue { get; set; }
public LineChartData1(Date Date2, Decimal MarketValue )
{
this.Date2 = Date2;
this.MarketValue = MarketValue ;
}
VF Page-
<apex:outputPanel id="LineData" style="width:100%; ">
<apex:pageblock id="Graph" title="Performance" >
<apex:chart height="300" width="500" data="{!mastermethod}">
<apex:axis type="Numeric" position="left" fields="Profile,MarketValue"
grid="true"/>
<apex:axis type="Category" position="bottom" fields="Date1">
</apex:axis>
<apex:lineSeries axis="left" fill="true" xField="Date1" yField="Profile"
markerType="cross" markerSize="4" markerFill="#FF0000"/>
<apex:lineSeries axis="left" xField="Date1" yField="MarketValue"
markerType="circle" markerSize="4" markerFill="#8E35EF"/>
<apex:legend position="right"/>
</apex:chart>
</apex:pageblock>
</apex:outPutPanel>