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

Message ListMessage List     Post MessagePost Message

  week number to date?
Posted by Michelle on Nov-19-2009 07:39
Hi guys, new to ChartDirector here, but I'm loving it so far.  I'm trying to automate chart creation (rather than my director using Excel) in Perl.  Anyways, I've got everything figured out, except for 1 thing. The data file I've got has the week number in the year, instead of the date. I can backtrack and change the original script to give me the date instead, but I was curious to know if there was some way in Chart Director to do a conversion. So, for labels on the X-axis, instead of having "1","2","3", etc..., it'd be set to jump every 4 weeks and just have "Jan", "Feb", "Mar". The reason I'm asking if this is possible is I believe it is in Excel, so I'm just curious if I could do the same type of thing here. Thanks!

  Re: week number to date?
Posted by Peter Kwan on Nov-19-2009 19:21
Hi Michelle,

Yes. You ask ChartDirector to jump every 4 weeks, but note that this is not Jan, Feb, Mar, etc.. Sometimes we need to jump 5 weeks for a month.

The exact month for a week depends on how do you define the "week number" (different people defines week number differently), and how you define which month a week falls into (should it be based on the start of the week, the Monday of the week, the end of the week, the middle of the week or something else)? We need these information to determine which month a week is on.

There are many methods to achieve what you need. One of the methods is like:

$currentMonth = -1;
for ($i = 0; $i < $noOfPoints; ++$i) {
    $month = findMonthGivenWeekNo($year, $weekNo[$i]);
    if ($month != $currentMonth) {
         #first week of a month
         $myLabels[$i] = $c->formatValue(perlchartdir::chartTime($year, $month, 1), "{value|mmm}");
         $currentMonth = $month;
    } else {
         $myLabels[$i] = "";
    }
}

#use $myLabels as the labels
$c->xAxis()->setLabels(\\@myLabels);

In the above code, findMonthGivenWeekNo is a function you need to write that determines the month of a week number. The above code assumes you are using a label based x-axis (the x-axis is configured using setLabels).

Hope this can help.

Regards
Peter Kwan