views:

90

answers:

2

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!

A: 

Hi

Even though you specify weeks, DateTimeAxis may still be using the hours and minutes values of the newly created date objects. You can format the date to set these to zero. Have a look at http://www.munkiihouse.com/?p=69, mention setting displayLocalTime=”true” in DateTimeAxis tag. Let us know if it works man

Brian Bishop
A: 

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:

case "weeks":
    d[hoursP] = 0;
    d[minutesP] = 0;
    d[secondsP] = 0;
    d[millisecondsP] = 0;
    if (d[dayP] != 0)
        d[dateP] = d[dateP] + (7 - d[dayP]);
    break;

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.

2DH
This sounds like the right approach. Thanks for helping me track down the specific piece of code in the DateTimeAxis source!
BuyTheBid