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

Message ListMessage List     Post MessagePost Message

  How to display months in equal distance along a year?
Posted by Eva on Oct-05-2011 00:56
Attachments:
I created a Gantt type chart and added a CDML table to display a fiscal year, quarters and months. I have a problem with aligning the label cells with the months, especially in the first half of the fiscal year.
How do I set this up? (I use Java)

Thanks,
Eva
Gantt Chart labels.png

  Re: How to display months in equal distance along a year?
Posted by Peter Kwan on Oct-05-2011 03:36
Hi Eva,

In your case, it seems the horizontal axis scale you are using is a true date/time axis scale, which means the length reflects the duration. It means each month should be of different length. In fact, by meaning the length between the grid lines, it seems the grid lines are for Jan, Feb, Mar, .... Dec. (The second cell is particularly short, suggesting it is Feb. The 7th and 8th cells are of the same long length, suggesting they are Jul and Aug.)

For your CDML table, each cell are of the same length, so they do not match the actual months.

To create the CDML table correct, you would need to configure the cell widths to match the duration of the months. I suggest you may use something like:

c.yAxis().setDateScale(new GregorianCalendar(2010, 4, 1).getTime(),
    new GregorianCalendar(2011, 4, 1).getTime(), 86400 * 30);
c.yAxis().setLabelFormat(" ");

.... draw chart as usual ....

//auto-scale axis, so that you can ask ChartDirector for the actual tick distances
c.layoutAxes();

double[] ticks = c.yAxis().getTicks();

CDMLTable t = c.addTable(0, 0, Chart.TopLeft, ticks.length - 1, 1);
for (int i = 0; i < ticks.length - 1; ++i) {
   //set the cell width to reflect the actual tick distance
   t.getColStyle(i).setWidth(c.getYCoor(ticks[i + 1]) - c.getYCoor(ticks[i]));
   t.setText(i, 0, "Month " + i);
}

... set up other rows ....

t.setPos(c.getPlotArea().getLeftX(), c.getPlotArea().getTopY() - t.getHeight());

Hope this can help.

Regards
Peter Kwan

  Re: How to display months in equal distance along a year?
Posted by Eva on Oct-12-2011 23:05
Thanks Peter! Your suggestion worked pretty good. The only problem I had was the size of the ticks[] array (double[] ticks = c.yAxis().getTicks();).
Sometimes it comes exactly the size of my month labels array, and I'm expecting
nTicks=(nLabels+1).
If there is some thing I should be aware of, please let me know.
Thanks again!
Eva

  Re: How to display months in equal distance along a year?
Posted by Peter Kwan on Oct-13-2011 01:15
Hi Eva,

The ticks array shows the number of labels on the axis. It may or may not be the same on the number of labels in your labels array, depending on the date range on the axis, and the size of your labels array.

One common confusion is about the duration of the axis. If you are using monthly ticks, and the axis starts at the beginning of a month, and the duration is exactly 1 year, there shoud be 13 ticks. However, in the following cases, there will not be 13 ticks:

(a) From 2010-1-1 to 2010-12-1. There is only 11 months. So there will not be 13 ticks.

(b) From 2010-1-1 to 2010-12-31. There is only 11 months 30 days, not 1 year. In programming language, new GregorianCalendar(2010, 12, 31).getTime() refers to the instance 2010-12-31 00:00:00, not the entire day 2010-12-31. So there will not be 13 ticks.

(c) From 2010-1-1 00:00:00 to 2010-12-31 23:59:59. It is still not 1 year (still miss 1 second).

For 13 monthly ticks, the date range should be from 2010-1-1 00:00:00 to 2011-1-1 00:00:00.

Hope this can help.

Regards
Peter Kwan

  Re: How to display months in equal distance along a year?
Posted by Eva on Oct-19-2011 03:44
Thank you, Peter for the explanation.  It makes sense.
It's working good now.
Thanks for the GREAT support!
Eva