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

Message ListMessage List     Post MessagePost Message

  Problem getting x Axis Date Ticks correct
Posted by Francis Greaves on Apr-18-2020 21:03
Attachments:
I have a graph with the x axis having data every minute for 30 days. This is 43200 items, so I only want to have Tick Marks every day or 86400 seconds.

As far as I can see from the API I should do this

c.xAxis().setDateScale(xAxisStart, xAxisEnd, 86400, 86400);

where the xAxisStart is the first and xAxisEnd is the last in the Date Array for the x axis.

Why do I not get the correct X Axis with ticks every day? See the result.
Lightning_Graph.png

  Re: Problem getting x Axis Date Ticks correct
Posted by Peter Kwan on Apr-19-2020 03:25
Hi Francis,

Your code should be correct.

For testing, you can try to hard code the dates to see if the labels are correct. For example (I assume you are using C# as the programming language):

xAxisStart = new DateTime(2020, 3, 19);
xAxisEnd = new DateTime(2020, 4, 18);
c.xAxis().setDateScale(xAxisStart, xAxisEnd, 86400, 86400);

If the hard coded dates work, but your real code does not work, one possibility is that the xAxisStart and xAxisEnd does not contain the dates you expect. In this case, please try the following code:

c.addTitle(xAxisStart.ToString() + " - " + xAxisEnd.ToString());

The start date and end date will then be displayed on the chart title. Please check to see if they are what you expect (that is, the two dates only differ by 30 days).


If even using hard coded dates, there are still to many labels, please make sure the there is no other lines that can add labels to the x-axis. For example, if your code calls Axis.setLabels, it will add more labels to the x-axis.


If the above still does not solve the problem, would you mind to inform me the charting part of your code?

Regards
Peter Kwan

  Re: Problem getting x Axis Date Ticks correct
Posted by Francis Greaves on Apr-19-2020 23:47
Attachments:
Magick!!!!! And I now have the Formatting sorted too.
Peter, you are a genius!
Many thanks for your time to answer this for me.
Francis
_LightningGraph.png

  Re: Problem getting x Axis Date Ticks correct
Posted by Francis Greaves on Apr-19-2020 17:29
Peter, thanks for such a quick reply. It was the Axis.setLabels that had done it!

I am using Java by the way.

Now I cannot see the items on the Bar Graph, just a white grid!!

Any ideas?

  Re: Problem getting x Axis Date Ticks correct
Posted by Peter Kwan on Apr-19-2020 21:08
Hi Francis,

If you cannot see the lines without Axis.setLabels, that means the LineLayer does not have x-coordinates. The line line should be added like:

LineLayer layer = c.addLineLayer(myDataArray, ....);
layer.setXData(myTimeStampsArray);

If you do not have setXData(myTimeStampsArrray) to provide the x-coordinates, then ChartDirector will assume the x-coordinates are the array index of your data (that is, the x-coordinates are 0, 1, 2, 3, ). If you configure the x-axis using Axis.setLabels, ChartDirector will also assume the x-coordinates for the labels to be array index 0, 1, 2, 3, .. So the data points matches the labels.

For your case, if you configure the x-axis using Axis.setDateScale, you would need to provide the x-coordinates too by using Layer.setXData.

Hope this can help.

Regards
Peter Kwan