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

Message ListMessage List     Post MessagePost Message

  Chart goes blank when trying to specify a range for the date on the x-axis
Posted by Tarek on Jul-13-2011 22:41
Hello,


Product: Chart Director
Version: 5.0.4.0
Development Language: C#
Operating System: Windows XP


I have an xychart which has data points spanning a 1 year and 3 months. However, I
want to specify the date range to go back only 3 months. (The reason I have 1 year and
3 months is because I need that data to be able to calculate the 200 day moving
average).

I tried the following method

Mychart.xaxis().setDateScale(DateTime.Today.AddMonths(-3),DateTime.Today)


This causes the chart to become blank.



Please let me know how I can get this simple issue fixed.


Regards,



Tarek K.

  Re: Chart goes blank when trying to specify a range for the date on the x-axis
Posted by Peter Kwan on Jul-14-2011 01:26
Hi Tarek,

I would need to see the charting part of the code to diagnose the issue. My guess is that your code has not set the x-coordinates of the data points (using Layer.setXData), but instead is trying to use a label based axis (using Axis.setLabels or Axis.setLabels2).

In a chart using a "date/time axis", the x-coordinates of the data points (which are date/time values) are set using Layer.setXData. ChartDirector can automatically set up the x-axis scale (just like it can automatically set up the y-axis scale). In a true date/time axis, the x-distance between the data points are proportional to the date/time between the data points. For example, if two data points are one day apart, and another two data points are 3 days apart, the x-distance of the second pair will be 3 times that of the first pair.

In a chart using a label based x-axis, there is no need to specify the x-coordinates using Layer.setXData. ChartDirector will assume the x-coordinates to be x = 0, 1, 2, 3. Your code can then specify the labels on the x-axis for x = 0, 1, 2, 3, ... using Axis.setLabels or Axis.setLabels. The labels can be anything, such as "Apple", "Oranges", "Jan 1, 2011", "1234546". You can certainly use arbitrary dates as labels.

However, if you are using a label based x-axis, and later set the x-axis scale using setDataScale, the chart will be empty. It is because the x-coordinates of the data points are still at x = 0, 1, 2, 3, ... and are not within the date range.

Typical finanical charts dos not use a true "date/time axis". It is a typically financial chart uses "trading days" as the x-axis, which are random and arbitrary. Yet all points should be equally spaced irrespective of whether the trading days are actually equal spaced or not. So a label based x-axis is usually used, which can use "arbitrary dates" as labels and all points will still be equally spaced.

If you would like a true date/time axis, please use Layer.setXData to pass the x-coordinates of the data points to ChartDirector. There is no need to use Axis.setLabels or Axis.setLabels2. You may want to use XYChart.setClipping to clip the chart to the plot area.

If you would like a label based x-axis, please pass only the data you want to display to ChartDirector. You can still use all the data to compute the moving average. After computing the moving average, please pass only the data you want to display to ChartDirector.

If you are using the FinanceChart object, you may use the "extraPoints" parameter in FinanceChart.setData to remove unwanted leading points. (There is no need to use Axis.setDateScale).

Hope this can help.

Regards
Peter kwan