Page 1 of 1

DateTime in TextSource

Posted: Sat Mar 17, 2007 1:23 am
by 9523566
With WindowsXP,VB2005.Net and TeeChart for .NET v2

Following my code comes error.
How to coding to get X-Values as datetime with textsource ?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If System.IO.File.Exists(Application.StartupPath & "\2007-03-16.txt") Then
Line1.Clear()
TextSource1.HeaderLines = 1
TextSource1.Separator = ","
TextSource1.Series = Line1
TextSource1.Fields.Add(0, "X")
TextSource1.Fields.Add(1, "Y")
TextSource1.LoadFromFile(Application.StartupPath & "\2007-03-16.txt")
End If
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TChart1.Aspect.View3D = False
TChart1.Legend.Visible = False
End Sub

--- 2007-03-16 Text File-----
2007/03/16 12:44:43,87.05,50.59
2007/03/16 12:44:45,82.57,44.08
2007/03/16 12:44:47,78.09,37.57
2007/03/16 12:44:49,73.6,31.06
2007/03/16 12:44:51,69.12,24.55
2007/03/16 12:44:53,64.64,58.04
2007/03/16 12:44:55,60.16,51.53

Thank you for prompt advice in advance.

Posted: Mon Mar 19, 2007 10:19 am
by 9348258
Hi

First you have to indicate that the X value of the serie is a DateTime, and then you can import the Chart. You can do something similiar as below code

Code: Select all

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Line1.XValues.DateTime = True
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ts As New Steema.TeeChart.Data.TextSource()
        Try
            Cursor = Cursors.WaitCursor
            ts.HeaderLines = 0
            ts.Separator = ","
            ts.Series = Line1
            ts.Fields.Add(0, "X")
            ts.Fields.Add(2, "Y")
            ts.LoadFromFile("c:\your_file.txt")
        Finally
            Cursor = Cursors.Default
        End Try
    End Sub