TeeChart.NET 2.0 Export Text file datetime type

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
scott
Newbie
Newbie
Posts: 13
Joined: Fri Mar 09, 2007 12:00 am

TeeChart.NET 2.0 Export Text file datetime type

Post by scott » Mon Mar 26, 2007 9:46 am

I use TeeChart.NET 2.0. I used WebChart and set Chart.XValues.DateTime = true, x value show in DateTime.
But when I use Export textformat, the xvalue in file always is float.

How can I to write datetime text in file?

My code:
string filename = Server.MapPath("~/App_Data/chart.txt");
Steema.TeeChart.Export.DataExport dataExport = new Steema.TeeChart.Export.DataExport(tChart1.Chart);
dataExport.Text.TextDelimiter = ",";
dataExport.Text.IncludeHeader = true;
dataExport.Text.IncludeIndex = false;
dataExport.Text.IncludeLabels = true;
dataExport.Text.Series = WebChart1.Chart.Series[0];
dataExport.Text.Save(filename);

Result text file:
X,Y
39106.6729166667,0
39106.6729166667,0
39106.6833333333,0
39106.6833333333,0
39106.69375,26.5299987792969
39106.69375,26.5299987792969
39106.7041666667,26.2299995422363
39106.7041666667,26.2299995422363
39106.7145833333,26.5299987792969
39106.725,25.6200008392334

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

Post by Narcís » Mon Mar 26, 2007 10:22 am

Hi scott,

You may be interested in reading this topic about a similar issue.
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

scott
Newbie
Newbie
Posts: 13
Joined: Fri Mar 09, 2007 12:00 am

Post by scott » Tue Mar 27, 2007 12:48 am

Hi Narcís:
Thank you for reply.
Before I post this problem, I already readed that article.
But I still don't understand how to export datetime text format file.
Will you write some sample to me?
Thank you very much.

p.s I use WebChart

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 27, 2007 1:58 pm

Hi scott,

In that case you'll have to save the file in a stream and then manipulate the double values into the string values of your choice. Something like this:

Code: Select all

		public Form1()
		{
			InitializeComponent();
			InitializeChart();
		}

		private Steema.TeeChart.Styles.Bar bar;
		private void InitializeChart()
		{
			tChart1.Series.Add(bar = new Steema.TeeChart.Styles.Bar());
			Random rnd = new Random();
			DateTime now = DateTime.Today;
			char label;
			for (int i = 0; i < 10; i++)
			{
				label = Convert.ToChar(65 + i);
				bar.Add(now, rnd.NextDouble(), label.ToString());
				now = now.AddDays(1);
			}
		}

		private void button1_Click(object sender, EventArgs e)
		{
			MemoryStream ms = new MemoryStream();
			string fileName = @"C:\temp\newexport.txt";
			tChart1.Export.Data.Text.IncludeHeader = true;
			tChart1.Export.Data.Text.IncludeIndex = false;
			tChart1.Export.Data.Text.IncludeLabels = true;
			tChart1.Export.Data.Text.Save(ms);
			ms.Position = 0;
			StreamReader reader = new StreamReader(ms);

			string line, newLine;
			string[] lines;
			DateTime date;
			StringBuilder result = new StringBuilder(1);

			if (tChart1.Export.Data.Text.IncludeHeader)
			{
				result.Append(reader.ReadLine() + tChart1.Export.Data.Text.TextLineSeparator);
			}
			while (!reader.EndOfStream)
			{
				line = reader.ReadLine();
				lines = line.Split(Convert.ToChar(tChart1.Export.Data.Text.TextDelimiter));
				if (lines.Length > 1)
				{
					date = DateTime.FromOADate(Convert.ToDouble(lines[1]));
					newLine = lines[0] + tChart1.Export.Data.Text.TextDelimiter + date.ToLongDateString() +
					 tChart1.Export.Data.Text.TextDelimiter + lines[2] + tChart1.Export.Data.Text.TextLineSeparator;
					result.Append(newLine);
				}
			}

			StreamWriter writer = new StreamWriter(fileName, false, System.Text.Encoding.Unicode);
			writer.Write(result.ToString());
			writer.Flush();
		}
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

scott
Newbie
Newbie
Posts: 13
Joined: Fri Mar 09, 2007 12:00 am

Post by scott » Wed Mar 28, 2007 3:10 am

Thank you Narcís:
This code is work. Now I understand your mean.
Export can't Save datetime format string.
We should write double first then transfer to datetime string.
Thank you angan!!

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

Post by Narcís » Wed Mar 28, 2007 12:18 pm

Hi scott,

You're welcome. I'm glad to hear this works fine at your end. We might consider adding the necessary properties to the export and import classes to do this automatically in future releases.
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