When I try to export data from TeeChart to XML, I get a weird double output of the coordinates. The X and Y attributes appear twice in each point element, like so:
<chart>
<series title="line" type="Line">
<points count="97">
<point X="38777.25" Y="138" X="38777.25" Y="138"/>
<point X="38777.2604166667" Y="135" X="38777.2604166667" Y="135"/>
<point X="38777.2708332176" Y="136" X="38777.2708332176" Y="136"/>
[snipped...]
</points>
</series>
<series title="Max. limit" type="Fast Line">
<points count="0">
</points>
</series>
</chart>
This doesn't happen with the other formats (I tried Text and Html). Any ideas why? Anything I can do about it? The code I'm using is:
tChart.Export.Data.XML.Save(@"C:\Scratch\testout.xml");
Weird double coordinates when Exporting to XML
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Arnold,
Thanks for reporting the issue. I could reproduce the issue and noticed that it only happens when adding X and Y values to the series not when only adding Y values. I've added it to our defect list (TF02011320) to be fixed for future releases. Actually there's no workaround I can think of.
Thanks for reporting the issue. I could reproduce the issue and noticed that it only happens when adding X and Y values to the series not when only adding Y values. I've added it to our defect list (TF02011320) to be fixed for future releases. Actually there's no workaround I can think of.
Best Regards,
Narcís Calvet / 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 |
Workaround
The workaround I'm using is to use the Text exporter and converting it to XML myself, by parsing it and rewriting. I'm doing it in memory to avoid unnecessary disk access:
MemoryStream pChartData = new MemoryStream();
tChart.Export.Data.Text.Series = myLine;
tChart.Export.Data.Text.Save(pChartData);
pChartData.Position = 0; //Resets stream to beginning
//Read text stream to string collection
StringCollection lstPoints = new StringCollection();
StreamReader pReader = new StreamReader(pTextChartData);
while(pReader.Peek > -1)
{
lstPoints.Add(pReader.ReadLine());
}
pReader.Close();
//Write out as xml
StreamWriter pWriter = new StreamWriter(@"C:\temp\testout.xml");
pWriter.WriteLine("<series title=\"line\" type=\"Line\">");
pWriter.WriteLine("<points count=\"{0}\">", lstPoints.Count);
foreach(string sPoint in lstPoints)
{
string[] sCoordinates = sPoint.Split("\t");
pWriter.WriteLine("<point X=\"{0}\" Y=\"{1}\"/>", sCoordinates[0], sCoordinates[1]);
}
pWriter.WriteLine("</points>");
pWriter.WriteLine("</series>");
pWriter.Close();
There are probably more elegant ways to do the conversion, but you get the idea...
MemoryStream pChartData = new MemoryStream();
tChart.Export.Data.Text.Series = myLine;
tChart.Export.Data.Text.Save(pChartData);
pChartData.Position = 0; //Resets stream to beginning
//Read text stream to string collection
StringCollection lstPoints = new StringCollection();
StreamReader pReader = new StreamReader(pTextChartData);
while(pReader.Peek > -1)
{
lstPoints.Add(pReader.ReadLine());
}
pReader.Close();
//Write out as xml
StreamWriter pWriter = new StreamWriter(@"C:\temp\testout.xml");
pWriter.WriteLine("<series title=\"line\" type=\"Line\">");
pWriter.WriteLine("<points count=\"{0}\">", lstPoints.Count);
foreach(string sPoint in lstPoints)
{
string[] sCoordinates = sPoint.Split("\t");
pWriter.WriteLine("<point X=\"{0}\" Y=\"{1}\"/>", sCoordinates[0], sCoordinates[1]);
}
pWriter.WriteLine("</points>");
pWriter.WriteLine("</series>");
pWriter.Close();
There are probably more elegant ways to do the conversion, but you get the idea...
Arnold Engelmann
DHI Water & Environment
DHI Water & Environment