Import Text with datetime

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
M.Takeda
Newbie
Newbie
Posts: 18
Joined: Tue Aug 17, 2004 4:00 am

Import Text with datetime

Post by M.Takeda » Mon Mar 19, 2007 12:28 pm

Thank you for your help to my questions.

Please accept my additionally question mentioned under.

In VB2005 and TeeChart foe NET V2,

----------- Export as text -----------------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim DataExport As New Steema.TeeChart.Export.DataExport(TChart1.Chart)

DataExport.Text.IncludeHeader = False
DataExport.Text.IncludeIndex = False
DataExport.Text.IncludeLabels = True
DataExport.Text.Series = Line1
DataExport.Text.Save(FileName)

End sub


This procedure makes text file as followings.
----- Exported File by Button1_Click ---
39159.7515823958 5.96103058474186
39159.7515939699 15.0420339196185
39159.751605544 14.3808898582966
39159.7516171181 14.1060914723697
39159.7516286921 14.1676675035468
39159.7516402662 3.56308315115193
39159.7516518403 18.5183631808117
----------------------------------------


with this text file,Button2_Click comes error.

-------- Import with TextSource -----------------
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Line1.XValues.DateTime = True

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") '---- Error because this field
not date string-----
ts.Fields.Add(2, "Y")
ts.LoadFromFile(FileName)
Finally
Cursor = Cursors.Default
End Try

End Sub

if Text is mentioned below, Button2_Click working fine.

------------------------------
2007/03/17 7:49:24,60.56,47.59
2007/03/17 7:49:24,73.32,24.34
2007/03/17 7:49:25,86.08,41.08
2007/03/17 7:49:26,68.84,57.83
2007/03/17 7:49:27,81.6,34.57
2007/03/17 7:49:28,64.36,51.31
2007/03/17 7:49:29,77.12,28.06
2007/03/17 7:49:30,89.88,44.8
2007/03/17 7:49:31,72.64,21.55
------------------------------

How can I do to solve it?

Is there the way to export datetime data as date string (Like above) ?

or is there the way to set (ts.Fields.Add(0,"X") as datetime from double?


Your kind advice will be highly appreciated.

Best Regards,

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Tue Mar 20, 2007 10:10 am

Hi M. Takeda,

It works fine here using the code below. The trick is that setting series to not have DateTime values before importing them. After the import has been done you can set DateTime values back again. As seen in Button2_Click method.

Code: Select all

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Line1.XValues.DateTime = True
		TChart1.Axes.Bottom.Labels.DateTimeFormat = "dd/mm/yyyy hh:mm:ss"

		Dim ts As New Steema.TeeChart.Data.TextSource()
		Try
			Cursor = Cursors.WaitCursor
			ts.HeaderLines = 0
			ts.DecimalSeparator = "."
			ts.Separator = ","
			ts.Series = Line1
			ts.Fields.Add(0, "X")
			ts.Fields.Add(1, "Y")

			ts.LoadFromFile("originalData.txt")
		Finally
			Cursor = Cursors.Default
		End Try

	End Sub

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim DataExport As New Steema.TeeChart.Export.DataExport(TChart1.Chart)

		DataExport.Text.IncludeHeader = False
		DataExport.Text.IncludeIndex = False
		DataExport.Text.IncludeLabels = True
		DataExport.Text.Series = Line1
		DataExport.Text.Save("data.txt")

	End Sub

	Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
		Line1.XValues.DateTime = False

		Dim ts As New Steema.TeeChart.Data.TextSource()
		Try
			Cursor = Cursors.WaitCursor
			ts.HeaderLines = 0
			ts.DecimalSeparator = ","
			ts.Separator = vbTab
			ts.Series = Line1
			ts.Fields.Add(0, "X")
			ts.Fields.Add(1, "Y")

			ts.LoadFromFile("data.txt")
		Finally
			Cursor = Cursors.Default
		End Try

		Line1.XValues.DateTime = True
		TChart1.Axes.Bottom.Labels.DateTimeFormat = "dd/mm/yyyy hh:mm:ss"
	End Sub
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply