1

I want to display month name in the last bar alone.i need output likeenter image description here but am getting output like this.how to add month in the last bar enter image description here

apex code:

public with sharing class Rfleet_VFPageReport {

public class Month {
   public Decimal year {get; set;}
    public Decimal volume{get; set;}


    Month(Decimal year,Decimal volume) {
       this.year = year;

        this.volume= volume;


    }
}

 public Month[] getMonths() {
    Month[] months = new Month[] {};
   for (AggregateResult ar : [select CALENDAR_YEAR(Current_month__c)Year,SUM(Countries_delivered_volume__c)Dvol from IKAM_Data__c
                                                             group by CALENDAR_YEAR(Current_month__c) order by CALENDAR_YEAR(Current_month__c) 
             ]) {                                        
                months.add(new Month((Decimal )ar.get('Year'),(Decimal)ar.get('Dvol')));
    }
    system.debug('------->'+months);
    return months;
}
}

VF:

<apex:page controller="Rfleet_VFPageReport" title="Deliveries By Year" >
<apex:form >
  <apex:pageBlock title="Deliveries By Year" >
     <style>
         .pbTitle{
                    text-align : center;
          }
      </style>

      <apex:chart height="400" width="400" data="{!months}" colorSet="#FFB547,#FFB547,#FFB547,#FFB547,#FFB547,#9ACD32" >

    <apex:axis type="Numeric" position="left" fields="volume" grid="true" >

     </apex:axis>
    <apex:axis type="Category" position="bottom" fields="year">

    </apex:axis>
    <apex:barSeries highlight="false" orientation="vertical" axis="left" tips="false" xField="year" yField="volume" colorsProgressWithinSeries="true">

   <apex:chartLabel field="volume" display="outside" orientation="horizontal"/>      
    </apex:barSeries>


         </apex:chart>
      </apex:pageBlock>
     </apex:form>
  </apex:page>    

1 Answer 1

1

It appears that your issue is that you're not comparing "apples to apples" in your chart. Your last data point is YTD, not an annual amount.

I see where you're using an aggregate query to return the monthly values for each month with a group by and order by clause on Calendar Year. You then use those monthly values for each calendar year without returning them as YTD values for each year along with the month.

If you did the latter, for previous calendar years, you could presumably conditionally render the month. If the value == December, render = false". If it's any other value, "render = true".

To help facilitate that, you'd also need to change the way you run your query. You currently specify this.year. Inside your for loop following your query you do something like below with decimals. I suggest you makes some revisions as I've indicated with comments:

integer mnthcount = 0;
Month[] months = new Month[] {};
    for (AggregateResult ar : [select CALENDAR_YEAR(Current_month__c)Year,SUM(Countries_delivered_volume__c)Dvol 
        from IKAM_Data__c group by CALENDAR_YEAR(Current_month__c) order by
         CALENDAR_YEAR(Current_month__c)]) {
            // add counter here
            integer count = 0;                           
            months.add(new Month((Decimal )ar.get('Year'),(Decimal)ar.get('Dvol')));
            // increment the counter to determine the number of months
            count++;
         }
         system.debug('------->'+months);
         return months;
         system.debug('number months = '+ count);
         mnthcount = count;
         return mnthcount;
    }  

It's not clear to me why you're using a decimal to get and set the year, but clearly an integer would do the job. If you were hoping to use the fraction to obtain the month, there doesn't appear to be anything in place to make that work for you. If anything, at the end of a calendar year, you'd have created the following year by totalling the sum of the months using that kind of methodology.

Because of that, you'll need to be careful when it comes to December. If you're to use this kind of methodology. You'll want to add logic that automatically makes the month value 13 for prior years when testing for months that are <=12. If not, each one will show as December and you'll have a problem with December of the current year.

So, in summary, you'll want to send this to your Visualforce label as something like 'year' + 'month' and have it conditionally render the month only if the month is < 13. I hope this is clearer than mud or that you at least get the general idea.

You should also be able to use JS to do some kind of show/hide or class swap based on the value of the month you send from the controller, or for that matter, could even compose the year/month using a method in your controller. Needless to say, there are a variety of options available to you.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .