ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Need help with the y-axis automatic time scale
Posted by Eva on Sep-21-2012 03:08
Attachments:
Hi Peter,

My Gantt chart may display different date ranges: from several years, to a year or even to a few or one month. To create time labels I?m using the code from the Zooming and scrolling demo example. I have not modify the code wanting to see what will happen.  The only difference is, I added the setLabelOffset(). This code works pretty well when I have several years scenario. But I would like to modify it a litle.

1. How do I display the ranges starting from the fiscal year, instead of the beginning of the calendar year?  Is it possible?  My fiscal year starts in October, for example FY 2013 is defined from Oct 1 2012 ? Sept 30, 2013.

2. Some of my bars are just few days long, but the chart always displays the whole year.  It seems the chart never uses the last condition chart.yAxis().setFormatCondition("align", 86400); I get only two types of time scale charts (I included them in the image).
If a task lasts one full day, which condition CD will apply?

3. How should I modify the code to display 1-day to 30-day tasks within just one month in weeks increments.

Here is the code:
// Set y-axis date scale to the view  date range.
      chart.yAxis().setDateScale(getViewStartDate(), getViewEndDate());

      // The y-axis range can be from many years to a few days. We can
      // let ChartDirector auto-determine the date/time format. However, for more beautiful
      // formatting, we set up several label formats to be applied at different conditions.

      // If all ticks are yearly aligned, then we use "yyyy" as the label format.
      chart.yAxis().setFormatCondition("align", 360 * 86400);
      chart.yAxis().setLabelFormat("FY{value|yyyy}");
      chart.yAxis().setLabelOffset(0.5 * Chart.TickInc);

      // If all ticks are monthly aligned, then we use "mmm yyyy" in bold font as the first
      // label of a year, and "mmm" for other labels.
      chart.yAxis().setFormatCondition("align", 30 * 86400);
      chart.yAxis().setMultiFormat(Chart.StartOfYearFilter(), "<*font=bold*>{value|mmm yyyy}",
          Chart.AllPassFilter(), "{value|mmm}");

      // If all ticks are daily aligned, then we use "mmm dd<*br*>yyyy" in bold font as the
      // first label of a year, and "mmm dd" in bold font as the first label of a month, and
      // "dd" for other labels.
      chart.yAxis().setFormatCondition("align", 86400);
      chart.yAxis().setMultiFormat(
          Chart.StartOfYearFilter(), "<*block,halign=left*><*font=bold*>{value|mmm dd<*br*>yyyy}",
          Chart.StartOfMonthFilter(), "<*font=bold*>{value|mmm dd}");
      chart.yAxis().setMultiFormat2(Chart.AllPassFilter(), "{value|dd}");

      // For all other cases (sub-daily ticks), use "hh:nn<*br*>mmm dd" for the first label of
      // a day, and "hh:nn" for other labels.
      chart.yAxis().setFormatCondition("else");
      chart.yAxis().setMultiFormat(Chart.StartOfDayFilter(), "<*font=bold*>{value|hh:nn<*br*>mmm dd}",
          Chart.AllPassFilter(), "{value|hh:nn}");

Thank you,
Eva
Dates.png

  Re: Need help with the y-axis automatic time scale
Posted by Peter Kwan on Sep-26-2012 05:47
Hi Eva,

Sorry for the late reply. I forgot to respond to your message. (I thought I had responded, but may be I had closed the browser before the message was really posted to the server.)

1. If ChartDirector is to auto-label the axis, and you have an axis range of many years, ChartDirector will put the labels (or the ticks or the major grid lines) at the calendar year boundary (that is, at Jan 1).

If you would like to use Fiscal Year instead, you would need to use additional code to specify the labels, rather than to let ChartDirector automatically choose the labels.

I am not sure of the nature of the getViewStartDate() and getViewEndDate() in your code. If for axis range that spans several years, those dates are always at fiscal year boundaries (or can be adjusted to fiscal year boundaries before passing to ChartDirector), then there is an easy solution:

if (.... getViewStartDate() and  getViewEndDate() is more than a few years ....)
{
     // assuming getViewStartDate() and getViewEndDate() are already at FY boundaries
     // so just put 1 label per year starting from getViewStartDate()
     chart.yAxis().setDateScale(getViewStartDate(), getViewEndDate(), 360 * 86400);
     chart.yAxis().setLabelFormat("FY{={value}+10000000|yy}");
else
{
     // Let ChartDirector auto-scale the axis

     ... put your original code here ...
}


2. ChartDirector determines the labelling method based on the axis range. In your code, the axis range is specified is by your code as getViewStartDate() to getViewEndDate(). Would you mind to verify if getViewStartDate() to getViewEndDate() are really a few days only for some charts? You may display the dates in the chart title or axis title so you can see them. For example, in Java:

c.addTitle(getViewStartDate().toString() + " to " + getViewEndDate().toString(), "Arial", 8);


3. How should I modify the code to display 1-day to 30-day tasks within just one month in weeks increments.

In your code, the axis labels do not depends on your "tasks". It only depends on the axis range you specified, which is getViewStartDate() to getViewEndDate(). If you want to display "one month" in weeks increments, make sure getViewStartDate() to getViewEndDate() is one month, and use:

//assume scale is one month, increment is 7 days
chart.yAxis().setDateScale(getViewStartDate(), getViewEndDate(), 7* 86400);
chart.yAxis().setLabelFormat("{value|mmm dd}");

Hope this can help.

Regards
Peter Kwan

  Re: Need help with the y-axis automatic time scale
Posted by Eva on Sep-27-2012 01:19
Thank you Peter for the explanation.

Would you mind to clarify the part "={value}+10000000" in the following statement from the first piece of the if clause:

chart.yAxis().setLabelFormat("FY{={value}+10000000|yy}");

What does 10,000,000 mean?

Eva

  Re: Need help with the y-axis automatic time scale
Posted by Peter Kwan on Sep-27-2012 02:23
Hi Eva,

In your case, a date at the year 2011 must be displayed as 2012. For example, Oct 2011 is displayed as FY12.

To do this, I add 10000000 seconds to the date before formatting it. 10000000 seconds is around 116 days. I figured after adding so many dates, the date Oct 2011 will become a date in the next year, so the format should show the next calender year.

Hope this can help.

Regards
Peter Kwan

  Re: Need help with the y-axis automatic time scale
Posted by Eva on Sep-27-2012 21:34
Thanks again Peter! It's a great way to resolve the FY dates. I like that idea.

Is there a reason why you picked ~116 days (10000000 secs) instead of 92 or 93?  There are 92 days from Oct 1, 2011 to Jan 1, 2012.  Would Sept 20, 2011 be calculated as in FY 2012 as well?  I'm going to do more testing now...

Eva

  Re: Need help with the y-axis automatic time scale
Posted by Peter Kwan on Sep-27-2012 22:49
Hi Eva,

I just randomly pick a number that works. I think you can pick any number from 92 days to 456 days.

Regards
Peter Kwan