Teechart Can't Handle Dates less than 1900???

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
jzarech
Newbie
Newbie
Posts: 58
Joined: Mon Jul 07, 2008 12:00 am

Teechart Can't Handle Dates less than 1900???

Post by jzarech » Sun Mar 02, 2014 12:52 am

DrawingBackwards.png
Years in the 1800's dates print backwards.
DrawingBackwards.png (29.82 KiB) Viewed 6238 times
I sell forecasts online and use this chart -- everything's been fine.
I created a forecast and dates dip into the 1800's and everything printed backwards on the chart.

Here's test code to show the problem:
vb.net

Dim dtTest as DateTime

dtTest = CDate("1/1/1809 2:00 am")
Me.TChart1.Series(0).Add(dtTest, 2)

dtTest = CDate("1/1/1809 3:00 am")
Me.TChart1.Series(0).Add(dtTest, 3)

dtTest = CDate("1/1/1809 4:00 am")
Me.TChart1.Series(0).Add(dtTest, 4)

Chart is defined with bottom axis as datetime and so is fastline series.

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.

I"m hoping it's some trick I didn't know or something simple.

thanks in advance anyone who can help me get past this challenge.

Joseph
Attachments
DrawingBackwardsCode.png
Code to replicate.
DrawingBackwardsCode.png (3.72 KiB) Viewed 6237 times
1900sNormal.png
Same chart with years changed to 1909 or 2009 works as expected -- not backwards.
1900sNormal.png (24.66 KiB) Viewed 6238 times

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Teechart Can't Handle Dates less than 1900???

Post by Christopher » Mon Mar 03, 2014 9:43 am

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
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Post Reply