I'm creating a VF pie chart where I need to display formula type field. I'm able to display the chart if using a picklist type field. However I need to display the chart using a formula type field. In my code, instead of 'Order_Type__c' (picklist field) I need to use a formula type field. Here is my code.
Page
<apex:sectionHeader subtitle="Pie Chart "/>
<apex:chart height="200" width="400" data="{!positionCountData}">
<apex:pieSeries dataField="posCount" labelField="Category"/>
<apex:legend position="right"/>
</apex:chart>
Controller
public List<PositionData> getPositionCountData () {
// SOQL query to get the count of positions by its functional area
List<AggregateResult> countdata = [select Sum(Amount__c) cnt,Order_Type__c
from Transaction__c
group by Order_Type__c];
// order by Category__c];
list<SelectOption> options = new list<SelectOption>();
// PickListController is used to get values from picklist since Functional area has datatype as picklist
options = PickListController.getPicklistValues(new Transaction__c (),'Order_Type__c');
// Position data is stored in a list
List<PositionData> posList = new List<PositionData>();
PositionData pos;
Integer j=0;
for (Integer i=0; i<options.size(); i++) {
pos = new PositionData();
String CatList = '';
String CatPickList = null;
if(i!=0) {
CatPickList = options[i-1].getLabel();
}
if(j < countdata.size()){
CatList = String.valueOf(countdata[j].get('Order_Type__c'));
}
if(CatPickList == CatList) {
pos.posCount = Double.valueOf(countdata[j].get('cnt'));
pos.Category = String.valueOf(countdata[j].get('Order_Type__c'));
pos.Category = CatPickList;
j++;
}
else{
pos.posCount = 0;
pos.Category = CatPickList;
}
posList.add(pos);
// In case there are positions without any specific functional area they are grouped under “Others”
if(i==0) {
pos.Category = '';
}
}
return posList;
}
// Wrapper class for Pie Chart
public class PositionData {
public Double posCount;
public String Category;
}