I’m using a CartesianChart with a DateTimeAxis to display weekly data in a Flex application. When I set dataUnits=”weeks” and labelUnits=”weeks” on the DateTimeAxis, it automatically places each major tick on a Sunday. However, I would like to provide users with the option of beginning the week on a Sunday or a Monday. How can I ask the DateTimeAxis to instead place the major ticks on a Monday (or some other day of week)?
For example, if the user is looking at total sum of something over the week, and requests that weeks start on a Sunday, the Series data would look like:
x: Date(July 11, 2010) y: 25
x: Date(July 18, 2010) y: 30
x: Date(July 25, 2010) y: 32
etc.
If the weeks start on a Monday, the Series data would instead look like:
x: Date(July 12, 2010) y: 22
x: Date(July 19, 2010) y: 33
x: Date(July 26, 2010) y: 29
etc.
With the second data set, the major ticks are still on July 11, July 18, July 25, etc. but the bars are slightly shifted off-center from the major ticks.
Thanks!
I looked at the code of DateTimeAxis class and I’m almost sure you can’t do what you want. If “alignLabelsToUnits” property is set to true (default) then labels are created by rounding Series data dates to appropriate units. In your case (weeks) it looks like this:
So as you can see, it checks if processed date is first day of the week (hard-coded 0), and if it is not, it’s changed to be such.
To achieve the behavior you seek, you’d probably have to override function for label creation and write another one for date rounding, as the default rounding function is declared private.