Thursday 7 February 2013

Piechart on VFpage with dynamic data


Page:
======

<apex:page controller="PieChartController1" title="Pie Chart" sidebar="false">
  <center>  <apex:chart height="350" width="450" data="{!pieData}">
        <apex:pieSeries dataField="data" labelField="name"/>
        <apex:legend position="right"/>
    </apex:chart>
   </center>
</apex:page>


Controller
========

public class PieChartController1 {
    public List<PieWedgeData> getPieData() {
        List<PieWedgeData> data = new List<PieWedgeData>();
        integer i=0;
        for(Opportunity opp:[select id,name,stagename,amount from Opportunity limit 10]){
            data.add(new PieWedgeData(opp.name,i++));      
       }
        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;
        }
    }
}

Output:
======



No comments:

Post a Comment

How to include a screen flow in a Lightning Web Component

 Hi, Assume  you have a flow called "Quick Contact Creation" and API Name for the same is "Quick_Contact_Creation". To i...