Share the post "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
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<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> |
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
hi, by page header, you mean what? 🙂
i was breaking my head the whole day on this. thanks for saving
you’re welcome dude
Thanks for this article.I had this problem and I couldn’t find resolve problem.But now all is well.
Thanks
@sarkhan: glad it helped you. please +1 this post 😀