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

Message ListMessage List     Post MessagePost Message

  Specifying what dates are shown on the X-Axis?
Posted by bert sirkin on May-27-2020 23:04
Attachments:
I'm creating 2 simple line graphs of values over a series of weeks (vb.net). Each graph is a separate layer.

The data that I'm providing to layer.setXData & layer2.setXData is a date array, which includes the week-ending dates.

I want the dates shown on the x-axis to be the exact dates that I specify in my array of dates, but ChartDirector is choosing what dates to show.

How can I have the specific week-ending dates that I provide be shown on the X-Axis?
x.jpg

  Re: Specifying what dates are shown on the X-Axis?
Posted by Peter Kwan on May-28-2020 16:22
Hi bert,

If you use setXData, by default, the x-axis will be auto-scaled just like the y-axis. You may have noticed the y-axis labels may not match your data exactly. For example, there are labels at $170000 and $210000, yet there may be no data value at exactly those values. The same would apply to the auto-scaled x-axis labels.

If you want to control the x-axis labels, there are several methods.

(a) If you know the full x-axis range you want, you can use something like:

' Set the x-axis scale from startDateTime to endDateTime with no labels
c.xAxis().setDateScale2(startDateTime, endDateTime, Nothing)

' Add the following labels
For i As Integer = 0 To Ubound(xDateTimeLabels)
     c.xAxis().addLabel(xDateTimeLabels(i), c.formatValue("{value|mmddyyyy}", xDateTimeLabels(i))
Next

(b) If your x-axis label positions are always regularly spaced starting from the first label position (eg. one label every 7 days starting from the 1st position), you can use:

' 7 * 86400 = 7 days (86400 is the number of seconds in one day)
c.xAxis().setDateScale(startDateTime, endDateTime, 7 * 86400)

(c) If your data points are always plotted as regularly spaced regardless of whether the dates/times are regularly spaced (as is in a typical financial chart), you can use Axis.setLabels instead of Layer.setXData.

Hope this can help.

Regards
Peter Kwan

  Re: Specifying what dates are shown on the X-Axis?
Posted by bert sirkin on May-28-2020 20:35
Thanks, Peter. That was extremely helpful!