Adobe Flex: Dates In Chart Not Displayed Correctly Using DateTimeAxis

Ever had that problem when using the DateTimeAxis along a horitonzalAxis or verticalAxis and when you hover over your mouse, the dates are not displayed correctly? That’s what happened to me when I first checked on using charts. The DateTimeAxis has a parseFunction property that lets you specify the function to use to convert, say, String dates to Date objects. The problem I encountered was that the dates displayed in the chart were subtracted a day. If your date is October 28, 2008, the date displayed in the chart would be October 27, 2008. There are two ways to solve this problem.

Adding displayLocalTime=”true” property in the DateTimeAxis

Or, using the code below to define your function to be used in the parseFunction to return a Date object

<mx:Script>
public function createDate(s:String):Date {
	var a:Array = s.split('/');
	newDate:Date = new Date(0);
	newDate.fullYear = a[2];
	newDate.month = a[0] - 1;	// minus 1 because months start from 0
	newDate.date = a[1];
	return newDate;
}
</mx:Script>
 
and from within the mx:horizontalAxis tag ...
 
<mx:horizontalAxis>
	<mx:DateTimeAxis dataUnits="days" parseFunction="createDate"/>
</mx:horizontalAxis>

Like what you see? Buy me a cup of coffee. Or subscribe to my feeds.


(No Ratings Yet)
 Loading ...

4 Responses to “Adobe Flex: Dates In Chart Not Displayed Correctly Using DateTimeAxis”

  1. 1
    concealed mind Says:

    hmm, how do I create a page header from this? Just thought you might know
    Ester’s Embracing Health, Ester’s Health Blog, Brief Sentiments

  2. 2
    tech Says:

    hi, by page header, you mean what? :)

  3. 3
    Athavan Raja Says:

    i was breaking my head the whole day on this. thanks for saving

  4. 4
    tech Says:

    you’re welcome dude

Leave a Reply