1

I am new to Visualforce Charting.

I have tried to create a chart but the value for X-Axis is not coming correctly. It's giving some junk value instead of Expiration Date.

Could anyone please help me to resolve this.

VF Page:-

 <apex:pageBlock >
   <apex:chart height="400" width="500" data="{!months}">
        <apex:axis type="Numeric" position="left" fields="count"
                title="Count of Opportunity ID" minimum="0" maximum="110" steps="10" dashSize="2"/>
        <apex:axis type="Category" position="bottom" fields="exDate"
                title="Actual HLA Expiry Date"/>
        <apex:barSeries orientation="vertical" axis="left"
                xField="exDate" yField="count"/>
   </apex:chart>
 </apex:pageBlock>

Controller:

 public class Month {
        public Date exDate {get; set;}
        public Integer count {get; set;}
        public String yearMonth {get; set; }
        Month(Date exDate, Integer count) {
            this.exDate = exDate;
            this.count = count;

        }
    }

    public Month[] getMonths() {
        Month[] months = new Month[] {};
        for (AggregateResult ar : [Select Count(id) c , HLA_Expiration_Date__c exp from Hardware_Loan_Agreement__c where HLA_Expiration_Date__c>=:Date.today() and HLA_Expiration_Date__c<=:Date.today().addDays(5) and Primary_Status__c = 'Proposal' Group By HLA_Expiration_Date__c Order by HLA_Expiration_Date__c]) {
            months.add(new Month(
                    (Date) ar.get('exp'),
                    (Integer) ar.get('c')
                    ));
        }
        return months;
    }

2
  • 4
    It's not "junk," it's a epoch time stamp (milliseconds since 1/1/1970). You might try using a String instead of a Date; just use the format method to convert the dates to strings.
    – sfdcfox
    Commented Jan 16, 2017 at 16:29
  • Hi @sfdcfox, Could you please help me with an example for using a String instead of a Date.
    – Sharma_raj
    Commented Jan 18, 2017 at 8:46

1 Answer 1

0

The chart is rendering your dates as "epoch time", which is simply the number of milliseconds since January 1st, 1970. You might want to use a string intead:

public class Month {
    public String exDate {get; set;}
    public Integer count {get; set;}
    public String yearMonth {get; set; }
    Month(Date exDate, Integer count) {
        this.exDate = exDate.format();
        this.count = count;
    }
}

You can adjust the formatting how you like.

2
  • Hi @sfdcfox, I have tried this public class Month { public Date exDate {get; set;} public Integer count {get; set;} public String yearMonth {get; set; } Month(Date exDate, Integer count) { this.exDate = exDate.format('d-MM-YYYY'); this.count = count; } } but getting an error as :- Error: dailyHLAReportDashboardController Compile Error: Method does not exist or incorrect signature: [Date].format(String) at line 31 column 27
    – Sharma_raj
    Commented Jan 18, 2017 at 13:46
  • @RAT__ The Date version of format doesn't accept a string format parameter. If you want to format it in a specific way, you'll have to convert it to a DateTime first. DateTime.newInstance(exDate, Time.newInstance(0,0,0,0)).format('d-MM-YYYY')
    – sfdcfox
    Commented Jan 18, 2017 at 13:48

You must log in to answer this question.

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