Page 1 of 1

Weird double coordinates when Exporting to XML

Posted: Thu Mar 16, 2006 2:14 am
by 9640494
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");

Posted: Thu Mar 16, 2006 4:25 pm
by narcis
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.

Workaround

Posted: Sat Mar 18, 2006 1:29 am
by 9640494
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...