jzarech wrote:If there's a limitation on printing dates in 1800's I didn't see it in the documentation and this control would then be worthless to me.
The explanation for this behaviour is as follows. CDate("1/1/1809 2:00 am") returns a negative double value, as can be seen in this simple test:
Code: Select all
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim dtTest As DateTime
dtTest = CDate("1/1/1809 2:00 am")
MessageBox.Show(dtTest.ToOADate().ToString())
End Sub
So when running code such as the following:
Code: Select all
Private Sub InitializeChart()
Dim dtTest As DateTime
Dim series As Line
series = New Line(tChart1.Chart)
dtTest = CDate("1/1/1809 2:00 am")
series.Add(dtTest, 2)
dtTest = CDate("1/1/1809 3:00 am")
series.Add(dtTest, 3)
dtTest = CDate("1/1/1809 4:00 am")
series.Add(dtTest, 4)
series.XValues.DateTime = True
tChart1.Axes.Bottom.Labels.Angle = 90
tChart1.Axes.Bottom.Labels.DateTimeFormat = "dd/MM/yyyy hh:mm:ss"
End Sub
where each consecutive XValue is a larger negative number, then the series plots 'correctly' with each larger negative number further to the left. There is a simple workaround to this that will need a little explanation. The zero point at which DateTime values cease to be negative can be seen using this code:
Code: Select all
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim dtTest As DateTime
dtTest = DateTime.FromOADate(0.0)
MessageBox.Show(dtTest.ToShortDateString() + " " + dtTest.ToShortTimeString())
End Sub
any DateTime value greater than "31/12/1899 0:00" will be positive and so more recent DateTime values than this will be plotted as larger positive numbers, that is to say, to the right of the previous ones. So, for plots involving DateTime values smaller than this we can use:
Code: Select all
tChart1.Axes.Bottom.Inverted = True
to invert the bottom axis and have larger negative values plot to the right of smaller negative values as if they were positive values, e.g.
Code: Select all
Private Sub InitializeChart()
Dim dtTest As DateTime
Dim series As Line
series = New Line(tChart1.Chart)
dtTest = CDate("1/1/1809 2:00 am")
series.Add(dtTest, 2)
dtTest = CDate("1/1/1809 3:00 am")
series.Add(dtTest, 3)
dtTest = CDate("1/1/1809 4:00 am")
series.Add(dtTest, 4)
series.XValues.DateTime = True
tChart1.Axes.Bottom.Labels.Angle = 90
tChart1.Axes.Bottom.Labels.DateTimeFormat = "dd/MM/yyyy hh:mm:ss"
tChart1.Axes.Bottom.Inverted = True
End Sub