Visualforce Bar Charts and Pie Chart

Visualforce Bar Charts and Pie Chart.

please find the more information on:

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_charting_appearance_bar_charts.htm

Visualforce page code:

<apex:page standardController="Account" extensions="ShowAccountPieChart">
    <apex:chart height="250" width="350" data="{!pieData}">
        <apex:pieSeries dataField="data" labelField="name"/>
        <apex:legend position="right"/>
    </apex:chart>
     <apex:outputPanel>
        <apex:pageblock title="Business Category Total Allowance" >
        <apex:chart height="250" width="600" data="{!pieData}">
            <apex:axis type="Numeric" position="left" fields="data" title="Allowed Visa"/> 
            <apex:axis type="Category" position="bottom" fields="name" title="Utilized Visa"/>         
            <apex:barSeries orientation="vertical" axis="left" xField="name" yField="data"/>
        </apex:chart>
    </apex:pageblock> 
    </apex:outputPanel>
</apex:page>

Apex controller:

public class ShowAccountPieChart{
 
    public ShowAccountPieChart(ApexPages.StandardController controller){
    //
    }
    public List<PieWedgeData> getPieData() {
        List<PieWedgeData> data = new List<PieWedgeData>();
        List<Account> memb = new List<Account>();
     
        //string accId = ApexPages.currentPage().getParameters().get('pv0');
        string accId = 'xxxx';
        string sql = 'SELECT Name,AllowedExhbitorsRollUp__c,Number_of_Visas_Utilised__c,Number_of_Cleaners_Utilised__c,Number_of_Maintenance_Staff_Utilised__c,IdCardRollUp__c,twpRollUp__c,FestivalVisaRollUp__c FROM Account where ID =:accId';
        memb = Database.Query(sql);
        for(Account a:memb){
            //data.add(new PieWedgeData('Allowance',Integer.valueof(a.AllowedExhbitorsRollUp__c)));
            data.add(new PieWedgeData('Visa Utilised',Integer.valueof(a.AllowedExhbitorsRollUp__c)/Integer.valueof(a.Number_of_Visas_Utilised__c)*10));
            data.add(new PieWedgeData('Cleaners Utilised',Integer.valueof(a.AllowedExhbitorsRollUp__c)/Integer.valueof(a.Number_of_Cleaners_Utilised__c)*10));
            data.add(new PieWedgeData('Maintenance Staff',Integer.valueof(a.AllowedExhbitorsRollUp__c)/Integer.valueof(a.Number_of_Maintenance_Staff_Utilised__c)*10));
            data.add(new PieWedgeData('GVAC',Integer.valueof(a.AllowedExhbitorsRollUp__c)/Integer.valueof(a.IdCardRollUp__c)*10));
            data.add(new PieWedgeData('Roll up',Integer.valueof(a.AllowedExhbitorsRollUp__c)/Integer.valueof(a.twpRollUp__c)*10));
            data.add(new PieWedgeData('Festival visa',Integer.valueof(a.AllowedExhbitorsRollUp__c)/Integer.valueof(a.FestivalVisaRollUp__c)*10));
        }
        /*
        data.add(new PieWedgeData('Jan', 30));
        data.add(new PieWedgeData('Jan', 30));
        data.add(new PieWedgeData('Feb', 15));
        data.add(new PieWedgeData('Mar', 10));
        data.add(new PieWedgeData('Apr', 20));
        data.add(new PieWedgeData('May', 20));
        data.add(new PieWedgeData('Jun', 5));
        */
        return data;
    }

    // Wrapper class
    public class PieWedgeData {

        public String name { get; set; }
        public Integer data { get; set; }

        public PieWedgeData(String name, Integer data) {
            this.name = name;
            this.data = data;
        }
    }
}


No comments:

Post a Comment