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

Message ListMessage List     Post MessagePost Message

  setting datetime x axis
Posted by Craig Roberts on Dec-31-2024 07:37
Hello Peter,

I am using XYChart and plotting a linelayer in vb.net.

I am trying to set the
c.xAxis.setDateScale(DateTime.Parse("2024-12-21 06:00"), DateTime.Parse("2024-12-22 06:00"))
to fix the c.xAxis startdate / enddate of chart

I am formatting as  c.xAxis.setLabelFormat("{value|hh:mn}")

my data labels looks like;

2024-12-21  06:01: AM
2024-12-21  06:06: AM
2024-12-21  06:11: AM
2024-12-21  06:16: AM
2024-12-21  06:21: AM
2024-12-21  06:26: AM


Problem : I cannot get the data to show

Any suggestions, I have checked forum and tried various things.

Regards
Craig Roberts

  Re: setting datetime x axis
Posted by Peter Kwan on Dec-31-2024 13:23
Hi Craig,

By "I cannot get the data to show", do you mean you cannot get the line in your LineLayer to show? Or are you referring to showing the axis labels?

If you can see the linelayer without the setDataScale, but you cannot see the line layer with setDateScale, it is likely because your LineLayer has no x-coordinates.

If you add a LineLayer without providing x-coordinates (using Layer.setXData), ChartDirector will automatically use the array index (0, 1, 2, 3, ...) as the x-coordinates.

If you use Axis.setLabels to add labels to the x-axis, the labels are just names and has no meaning to ChartDirector. (The labels can be "Apple", "2024-12-31 06:00", "999" or any text.) They are displayed as is. The x-coordinates of the labels are also its array index (0, 1, 2, 3, ...). That's why the data points and the will match.

The following is an example that uses no x-coordinates:

https://www.advsofteng.com/doc/cdnet.htm#symbolline2.htm

If you then configure the x-axis with setDateScale, it will not match the automatic x-coordinates (0, 1, 2, 3. ...) for the LineLayer, so the line may not be visible. That means if you use setDataScale, you also need to provide the x-coordinates for the data points.

The following is an example:

https://www.advsofteng.com/doc/cdnet.htm#unevenpoints.htm

If the above still does not solve problem, would you mind to inform me of your code that adds and set up the LineLayer ?


Best Regards
Peter Kwan

  Re: setting datetime x axis
Posted by Craig Roberts on Jan-06-2025 08:03
Thanks Peter, I was able to get it to work by the following;

by setting layer.setXData to Labels(array of datetime)
and setting  c.xAxis().setDateScale to the start datetime and end datetime

  Dim layer As LineLayer = c.addLineLayer()
  layer.addDataSet(data, &HFF0000)
  layer.setXData(labels)

  c.xAxis().setDateScale(_StartDate, _EndDate)
  c.yAxis().setLabelStyle("Arial", 10)
  c.xAxis().setLabelFormat("{value|hh:nn}")

Only issue, with line layer it joins the gaps in data on the datetimes.

Thanks
Craig Roberts

  Re: setting datetime x axis
Posted by Peter Kwan on Jan-06-2025 16:00
Hi Craig,

For a line chart, ChartDirector will join the points with line segments. It is common for line charts to have unevenly spaced data points, so ChartDirector will not leave a gap simply because the spacing between two points are larger than the other points.

To leave a gap, you may include a Chart.NoValue point. See:

https://www.advsofteng.com/doc/cdnet.htm#missingpoints.htm

Hope this can help.

Regards
Peter Kwan