Adobe Flex: Dates In Chart Not Displayed Correctly Using DateTimeAxis
Posted by tech on
October 23, 2008
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>




October 23rd, 2008 at 8:47 am
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
October 23rd, 2008 at 8:26 pm
hi, by page header, you mean what?
January 12th, 2009 at 3:04 am
i was breaking my head the whole day on this. thanks for saving
January 12th, 2009 at 3:09 am
you’re welcome dude