Page 1 of 1

TeeChart.NET 2.0 Export Text file datetime type

Posted: Mon Mar 26, 2007 9:46 am
by 9644471
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

Posted: Mon Mar 26, 2007 10:22 am
by narcis
Hi scott,

You may be interested in reading this topic about a similar issue.

Posted: Tue Mar 27, 2007 12:48 am
by 9644471
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

Posted: Tue Mar 27, 2007 1:58 pm
by narcis
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();
		}

Posted: Wed Mar 28, 2007 3:10 am
by 9644471
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!!

Posted: Wed Mar 28, 2007 12:18 pm
by narcis
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.