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

Message ListMessage List     Post MessagePost Message

  Use end-of-month as axis label
Posted by Steve on Aug-03-2011 20:52
I have an XY chart with dates along the x-axis.  The data is monthly (with data points falling on the last calendar day of each month).  All other days in each month have no data.

I have formatted the x-axis labels like so (where c is the XYChart object):
c->xAxis()->setLabelFormat("{value|mmm-yy}");

ChartDirector has monthly labels appearing at the *start* of each month, which means the data in my chart appears to be offset by a month.  What I want to do is have the axis labels appear at the end of each month.  For example, I want "Mar-11" to appear on 31st March 2011, not 1st March 2011.

Thanks in advance for your help,

Steve

  Re: Use end-of-month as axis label
Posted by Peter Kwan on Aug-04-2011 01:50
Hi Steve,

There are several methods to achieve the chart you need.

(a) One easy method is to simply modify your data to use the first day of the month for all your data points. Note that it is not important which day of the month you use if the day is not visible in the chart (the label format is "mmm-yy"). The important thing is that the "mmm-yy" appears on the axis, and your data points are aligned with the labels.

If your data come from an SQL query, you can use a modified query to obtain the date in which the day part is hard coded to 1. Alternative, you may iterate your x-data array and modify the day part to 1.

(b) If you always have one data point per month, you may use a label based x-axis. The code is like:

c->addLineLayer(myYData, ....);
c->xAxis()->setLabels2(myXData, "{value|mmm-yy}");

If you have a large number of data points, and you do not want to show one label for each point, you may use setLabelStep to skip some labels, like:

//skip some labels to ensure the label distance is at least 50 pixels
c->xAxis()->setLabelStep((myXData.Length * 50 - 1) / c->getPlotArea()->getWidth() + 1);

(c) Other methods include using Axis.setDateScale2 to set up an axis with no label at first, and then use Axis.addLabel to add the labels at the location you want; or to use BaseChart.layout to auto-scale the axis first, then use Axis.getTicks and Axis.addLabel to shift the auto-scale labels to the end of the month.

Hope this can help.

Regards
Peter Kwan