function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Raghavendra M 13Raghavendra M 13 

number of opportunities sold by month using lightning component?

Month field :
Data Type: Formula  
CASE(MONTH(CloseDate), 1, "January", 2, "February", 3, "March", 4, "April", 5, "May", 6, "June", 7, "July", 8, "August", 9, "September", 10, "October", 11, "November", 12, "December", "None")

Apex Class:
public class NoofOpportunitiesbymonth{
    public static List<MonthWrapper> oppMonth(){
        List<MonthWrapper> wrapper = new List<MonthWrapper>() ; 
        AggregateResult[] Result = [SELECT Count(Id) Total ,
                                    Month__c Months FROM Opportunity GROUP BY Month__c limit 10];
        for (AggregateResult ar : Result) {
            wrapper.add(new MonthWrapper((String)ar.get('Months') ,(Integer)ar.get('Total')));
        return wrapper ;
    public class MonthWrapper{
        public String month{get;set;}
        public Integer count {get;set;}
        public MonthWrapper(String month, Integer count){
            this.month= month;
            this.count = count; 
<aura:component controller="NoofOpportunitiesbymonth" implements="force:appHostable" >
    <aura:attribute name="opportunities" type="List[]"/>
    <aura:handler name="init" value="{!this}" action="{!c.myAction}"/>
    <table border="1" class="table">
            <th>Number of Opportunities&nbsp;</th>
        <aura:iteration items="{!v.opportunities}" var="cust">
    myAction : function(component, event, helper) {
        var action =component.get("c.oppMonth");
        console.log('The action value is: '+action);
         action.setCallback(this, function(a){ 
            component.set("v.opportunities", a.getReturnValue());
            console.log('The opps are :'+JSON.stringify(a.getReturnValue()));