Export WPF TeeChart to XAML. Real numbers serialization bug.

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
neurosoft
Newbie
Newbie
Posts: 12
Joined: Mon Jun 04, 2012 12:00 am

Export WPF TeeChart to XAML. Real numbers serialization bug.

Post by neurosoft » Tue Oct 09, 2012 8:00 am

Hello Steema!
I've got new bug with the new version of WPF TeeChart. The problem is in serialization of real numbers when I try to export TeeChart to XAML. Decimal separator of that numbers must be invariant - dot, not comma for any locale!
For example, if I set TeeChart width to 300.5 and height to 200

Code: Select all

MyTChart.Width = 300.5;
MyTChart.Height = 200;  
and then export TeeChart to XAML

Code: Select all

MyTChart.Export.Image.XAML.Save(@"D:\test.xaml");
I have bad values of some real numbers:
<Canvas Name="MyTChart" Width="300.5" Height="200" Background="#FFF0F0F0" ClipToBounds="True" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006 ... esentation" >
<Rectangle
Canvas.Left="0" Canvas.Top="0" Width="301.5" Height="201">
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Offset="0" Color="#FFEAEAEA"/>
<GradientStop Offset="1" Color="#FFFFFFFF"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Line X1="0" X2="299,5" Y1="0" Y2="0" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="0" X2="0" Y1="0" Y2="199" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="0" X2="299,5" Y1="199" Y2="199" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="299,5" X2="299,5" Y1="199" Y2="0" StrokeThickness="1" Stroke="#FF000000"/>
<TextBlock Canvas.Left="121.5" Canvas.Top="9.5" Foreground="#FF000080" FontFamily="Verdana" FontSize="11.2" >
TeeChart
</TextBlock>
<TextBlock Canvas.Left="121.5" Canvas.Top="9.5" Foreground="#FF000080" FontFamily="Verdana" FontSize="11.2" >
TeeChart
</TextBlock>
<Polygon Points="21,51 284.5,51 284.5,166 21,166 ">
<Polygon.Fill>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Offset="0" Color="#FFEAEAEA"/>
<GradientStop Offset="1" Color="#FFFFFFFF"/>
</LinearGradientBrush>
</Polygon.Fill>
</Polygon>
<Line X1="21" X2="284,5" Y1="51" Y2="51" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="284,5" X2="284,5" Y1="51" Y2="166" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="284,5" X2="21" Y1="166" Y2="166" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="21" X2="21" Y1="166" Y2="51" StrokeThickness="1" Stroke="#FF000000"/>
<Polygon Fill="#FFFFFFE0" Points="16,56 21,51 21,166 16,171 "/>
<Line X1="16" X2="21" Y1="56" Y2="51" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="21" X2="21" Y1="51" Y2="166" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="21" X2="16" Y1="166" Y2="171" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="16" X2="16" Y1="171" Y2="56" StrokeThickness="1" Stroke="#FF000000"/>
<Polygon Fill="#FFFFFFFF" Points="16,171 279.5,171 284.5,166 21,166 "/>
<Line X1="16" X2="279,5" Y1="171" Y2="171" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="279,5" X2="284,5" Y1="171" Y2="166" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="284,5" X2="21" Y1="166" Y2="166" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="21" X2="16" Y1="166" Y2="171" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="16" X2="16" Y1="56" Y2="171" StrokeThickness="2" Stroke="#FF404040"/>
<Line X1="284,5" X2="284,5" Y1="51" Y2="166" StrokeThickness="2" Stroke="#FF404040"/>
<Line X1="21" X2="285" Y1="51" Y2="51" StrokeThickness="2" Stroke="#FF404040"/>
<Line X1="16" X2="280" Y1="171" Y2="171" StrokeThickness="2" Stroke="#FF404040"/>
</Canvas>
See bold text (coordinates of lines).

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Export WPF TeeChart to XAML. Real numbers serialization bug.

Post by Sandra » Tue Oct 09, 2012 3:14 pm

Hello Neurosoft,

Could you send us a simple project so we can reproduce your exactly problem here?

Thanks,
Best Regards,
Sandra Pazos / 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

neurosoft
Newbie
Newbie
Posts: 12
Joined: Mon Jun 04, 2012 12:00 am

Re: Export WPF TeeChart to XAML. Real numbers serialization bug.

Post by neurosoft » Wed Oct 10, 2012 6:12 am

Hello Sandra!
I attached simple project to reproduce the problem. We use the latest version of TeeChart.WPF.dll (4.1.2012.9283). To reproduce the bug ensure that decimal separator in 'Language and Region' -> 'Formats' -> 'Additional Settings' (http://windows.microsoft.com/en-US/wind ... asurements) is comma (","), not dot. Then launch attached application and click 'export' button. Some values of line coordinates in result XAML file will contain comma. That is wrong, because decimal separators must be same in all file (only dot, not comma or dot).

PS. We already have posted the similar problem here (see http://www.teechart.net/support/viewtop ... =4&t=12729).
Attachments
RealNumbersInLines.zip
(43.96 KiB) Downloaded 621 times

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Export WPF TeeChart to XAML. Real numbers serialization bug.

Post by Sandra » Thu Oct 11, 2012 8:32 am

Hello neurosoft,

Thanks for your project. I have checked it using to default decimal separation as dot, and I have gotten a correct results as you can see in next lines:

Code: Select all

<Canvas Name="MyTChart" Width="300.5" Height="200" Background="#FFF0F0F0" ClipToBounds="True" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" >
<Rectangle
 Canvas.Left="0" Canvas.Top="0" Width="301.5" Height="201">
 <Rectangle.Fill>
   <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
    <GradientStop Offset="0" Color="#FFEAEAEA"/>
    <GradientStop Offset="1" Color="#FFFFFFFF"/>
  </LinearGradientBrush>
 </Rectangle.Fill>
</Rectangle>
<Line X1="0" X2="299.5" Y1="0" Y2="0" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="0" X2="0" Y1="0" Y2="199" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="0" X2="299.5" Y1="199" Y2="199" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="299.5" X2="299.5" Y1="199" Y2="0" StrokeThickness="1" Stroke="#FF000000"/>
<TextBlock Canvas.Left="121.5" Canvas.Top="9.5" Foreground="#FF000080" FontFamily="Verdana" FontSize="11.2" >
TeeChart
</TextBlock>
<TextBlock Canvas.Left="121.5" Canvas.Top="9.5" Foreground="#FF000080" FontFamily="Verdana" FontSize="11.2" >
TeeChart
</TextBlock>
<Polygon
 Points="21,51 284.5,51 284.5,166 21,166 ">
 <Polygon.Fill>
   <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
    <GradientStop Offset="0" Color="#FFEAEAEA"/>
    <GradientStop Offset="1" Color="#FFFFFFFF"/>
  </LinearGradientBrush>
 </Polygon.Fill>
</Polygon>
<Line X1="21" X2="284.5" Y1="51" Y2="51" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="284.5" X2="284.5" Y1="51" Y2="166" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="284.5" X2="21" Y1="166" Y2="166" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="21" X2="21" Y1="166" Y2="51" StrokeThickness="1" Stroke="#FF000000"/>
<Polygon Fill="#FFFFFFE0"
 Points="16,56 21,51 21,166 16,171 "/>
<Line X1="16" X2="21" Y1="56" Y2="51" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="21" X2="21" Y1="51" Y2="166" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="21" X2="16" Y1="166" Y2="171" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="16" X2="16" Y1="171" Y2="56" StrokeThickness="1" Stroke="#FF000000"/>
<Polygon Fill="#FFFFFFFF"
 Points="16,171 279.5,171 284.5,166 21,166 "/>
<Line X1="16" X2="279.5" Y1="171" Y2="171" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="279.5" X2="284.5" Y1="171" Y2="166" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="284.5" X2="21" Y1="166" Y2="166" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="21" X2="16" Y1="166" Y2="171" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="16" X2="16" Y1="56" Y2="171" StrokeThickness="2" Stroke="#FF404040"/>
<Line X1="284.5" X2="284.5" Y1="51" Y2="166" StrokeThickness="2" Stroke="#FF404040"/>
<Line X1="21" X2="285" Y1="51" Y2="51" StrokeThickness="2" Stroke="#FF404040"/>
<Line X1="16" X2="280" Y1="171" Y2="171" StrokeThickness="2" Stroke="#FF404040"/>
And also I have made the same test using decimal separator as coma, and it works fine to me as you can see in next lines:

Code: Select all

<Canvas Name="MyTChart" Width="300.5" Height="200" Background="#FFF0F0F0" ClipToBounds="True" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" >
<Rectangle
 Canvas.Left="0" Canvas.Top="0" Width="301.5" Height="201">
 <Rectangle.Fill>
   <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
    <GradientStop Offset="0" Color="#FFEAEAEA"/>
    <GradientStop Offset="1" Color="#FFFFFFFF"/>
  </LinearGradientBrush>
 </Rectangle.Fill>
</Rectangle>
<Line X1="0" X2="299.5" Y1="0" Y2="0" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="0" X2="0" Y1="0" Y2="199" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="0" X2="299.5" Y1="199" Y2="199" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="299.5" X2="299.5" Y1="199" Y2="0" StrokeThickness="1" Stroke="#FF000000"/>
<TextBlock Canvas.Left="121.5" Canvas.Top="9.5" Foreground="#FF000080" FontFamily="Verdana" FontSize="11.2" >
TeeChart
</TextBlock>
<TextBlock Canvas.Left="121.5" Canvas.Top="9.5" Foreground="#FF000080" FontFamily="Verdana" FontSize="11.2" >
TeeChart
</TextBlock>
<Polygon
 Points="21,51 284.5,51 284.5,166 21,166 ">
 <Polygon.Fill>
   <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
    <GradientStop Offset="0" Color="#FFEAEAEA"/>
    <GradientStop Offset="1" Color="#FFFFFFFF"/>
  </LinearGradientBrush>
 </Polygon.Fill>
</Polygon>
<Line X1="21" X2="284.5" Y1="51" Y2="51" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="284.5" X2="284.5" Y1="51" Y2="166" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="284.5" X2="21" Y1="166" Y2="166" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="21" X2="21" Y1="166" Y2="51" StrokeThickness="1" Stroke="#FF000000"/>
<Polygon Fill="#FFFFFFE0"
 Points="16,56 21,51 21,166 16,171 "/>
<Line X1="16" X2="21" Y1="56" Y2="51" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="21" X2="21" Y1="51" Y2="166" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="21" X2="16" Y1="166" Y2="171" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="16" X2="16" Y1="171" Y2="56" StrokeThickness="1" Stroke="#FF000000"/>
<Polygon Fill="#FFFFFFFF"
 Points="16,171 279.5,171 284.5,166 21,166 "/>
<Line X1="16" X2="279.5" Y1="171" Y2="171" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="279.5" X2="284.5" Y1="171" Y2="166" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="284.5" X2="21" Y1="166" Y2="166" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="21" X2="16" Y1="166" Y2="171" StrokeThickness="1" Stroke="#FF000000"/>
<Line X1="16" X2="16" Y1="56" Y2="171" StrokeThickness="2" Stroke="#FF404040"/>
<Line X1="284.5" X2="284.5" Y1="51" Y2="166" StrokeThickness="2" Stroke="#FF404040"/>
<Line X1="21" X2="285" Y1="51" Y2="51" StrokeThickness="2" Stroke="#FF404040"/>
<Line X1="16" X2="280" Y1="171" Y2="171" StrokeThickness="2" Stroke="#FF404040"/>
My conclusion is that the export of xaml works fine in last version of TeeChartFor.Net. On the other hand, if you want that the decimal separation is fixed dot, for each cultures you only need change previously to export cultureinfo.invariantculture as explain in next link:
http://msdn.microsoft.com/en-us/library ... lture.aspx


Thanks,
Best Regards,
Sandra Pazos / 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

neurosoft
Newbie
Newbie
Posts: 12
Joined: Mon Jun 04, 2012 12:00 am

Re: Export WPF TeeChart to XAML. Real numbers serialization bug.

Post by neurosoft » Thu Oct 11, 2012 10:13 am

Sandra. I don't know what you actualy did. But I have a problem.
If I set decimal separator (http://windows.microsoft.com/en-US/wind ... asurements) to dot or change region to English(USA), export works fine. Real numbers does not contain commas - only dots. But if I set region to Russian or Spanish, or set decimal separator to dot, line coordinates contains commas in result XAML. Do you believe me? If you do, then just set invariant culture in ToString() arguments when you serialize to string line coordinates values. I cant do that. The link, that you posted, describes how to serialize to string a Date, Number, etc. TChart class does not have methods to export itself to XAML with target culture.
So I am sure, that you have to set invariant culture when you serialize line coordinates. If you think, that I have to do it, show me the code, which exports TCHart to XAML properly in any Culture (English, Russian, Spanish...).

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Export WPF TeeChart to XAML. Real numbers serialization bug.

Post by Sandra » Thu Oct 11, 2012 3:19 pm

Hello neurosoft,

Thanks for your explanation. I inform you we have fixed the problem for next maintenance release of TeeChartFor.Net. On the other hand, if you have the source code to solve the problem you only need make next changes in CanvasXAML.cs file:


Original code:

Code: Select all

  public override void LineTo(int x, int y)
#endif
    {
			if (IClipGeometry != null)
			{
				AddToStream("<Line X1=\"" + fx.ToString() + "\" X2=\"" + x.ToString() +
					 "\" Y1=\"" + fy.ToString() + "\" Y2=\"" + y.ToString() + "\" " + XAMLPen() + ">");
				XAMLClip("Line", Utils.FromLTRB(fx, fy, x, y), true);
				AddToStream("</Line>");
			}
			else
			{
				AddToStream("<Line X1=\"" + fx.ToString() + "\" X2=\"" + x.ToString() +
						"\" Y1=\"" + fy.ToString() + "\" Y2=\"" + y.ToString() + "\" " + XAMLPen() + "/>");
			}
			fx = x;
			fy = y;
		}
Fix problem code:

Code: Select all

	 public override void LineTo(int x, int y)
#endif
    {
			if (IClipGeometry != null)
			{
				AddToStream("<Line X1=\"" + FloatToStr(fx) + "\" X2=\"" + FloatToStr(x) +
					 "\" Y1=\"" + FloatToStr(fy) + "\" Y2=\"" + FloatToStr(y) + "\" " + XAMLPen() + ">");
				XAMLClip("Line", Utils.FromLTRB(fx, fy, x, y), true);
				AddToStream("</Line>");
			}
			else
			{
				AddToStream("<Line X1=\"" + FloatToStr(fx) + "\" X2=\"" + FloatToStr(x) +
						"\" Y1=\"" + FloatToStr(fy) + "\" Y2=\"" + FloatToStr(y) + "\" " + XAMLPen() + "/>");
			}
			fx = x;
			fy = y;
		}

As you see the change consist in change fx.ToString to FloatToStr(fx) because works for each cultures.

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / 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

neurosoft
Newbie
Newbie
Posts: 12
Joined: Mon Jun 04, 2012 12:00 am

Re: Export WPF TeeChart to XAML. Real numbers serialization bug.

Post by neurosoft » Fri Oct 12, 2012 5:01 am

Thank you, Sandra!
Unfortunately, I have not the source code. So, I will wait the fix in next release.

Post Reply