TrendFunction: YValues set to XValues

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Trimble Terrasat
Newbie
Newbie
Posts: 16
Joined: Tue Apr 25, 2006 12:00 am

TrendFunction: YValues set to XValues

Post by Trimble Terrasat » Tue Apr 21, 2009 11:34 am

Hello,

I have code as follows:

Code: Select all

Line line = new Line();
line.DataSource = lineTemp;

TrendFunction trend = new TrendFunction();
trend.PeriodAlign = PeriodAligns.Center;
trend.PeriodStyle = PeriodStyles.NumPoints;
trend.Period = line.Count;
line.Function = trend;
Sometimes, especially if the number of points in the line is quite small, the XValues are written into the YValues instead of calculating the YValues via the trend function. For us this seems to be a bug. Do you know more about this?

Kind regards

Jens

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 Apr 21, 2009 12:55 pm

Hi Jens,

I'm not able to reproduce the problem here using code snippet below. Could you please modify it so that we can reproduce the problem here and let us know the TeeChart version you are using?

Code: Select all

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

    private void InitializeChart()
    {
      Steema.TeeChart.Styles.Line lineTemp = new Steema.TeeChart.Styles.Line(tChart1.Chart);
      lineTemp.FillSampleValues(5);

      Steema.TeeChart.Styles.Line line = new Steema.TeeChart.Styles.Line(tChart1.Chart);
      line.DataSource = lineTemp;

      Steema.TeeChart.Functions.TrendFunction trend = new Steema.TeeChart.Functions.TrendFunction();
      trend.PeriodAlign = Steema.TeeChart.Functions.PeriodAligns.Center;
      trend.PeriodStyle = Steema.TeeChart.Functions.PeriodStyles.NumPoints;
      trend.Period = line.Count;
      line.Function = trend;
    }
Thanks in advance.
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

Trimble Terrasat
Newbie
Newbie
Posts: 16
Joined: Tue Apr 25, 2006 12:00 am

Post by Trimble Terrasat » Tue Apr 21, 2009 2:07 pm

Hi Narcís,

with the following code I can reproduce:

Code: Select all

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

private void InitializeChart()
{
	Steema.TeeChart.Styles.Line lineTemp = new 
                    Steema.TeeChart.Styles.Line( tChart1.Chart );
	lineTemp.Add( 924266611, 1.1 );
	lineTemp.Add( 924266612, 1.2 );
	lineTemp.Add( 924266613, 1.3 );
	lineTemp.Add( 924266614, 1.4 );
	lineTemp.Add( 924266615, 1.5 );

	Steema.TeeChart.Styles.Line line = new 
                    Steema.TeeChart.Styles.Line( tChart1.Chart );
	line.DataSource = lineTemp;

	Steema.TeeChart.Functions.TrendFunction trend = new 
                    Steema.TeeChart.Functions.TrendFunction();
	trend.PeriodAlign = 
                    Steema.TeeChart.Functions.PeriodAligns.Center;
	trend.PeriodStyle = 
                    Steema.TeeChart.Functions.PeriodStyles.NumPoints;
	trend.Period = line.Count;
	line.Function = trend;
}
The problem seems to occur with large x values. There seems to be no internal reduction of the x values for the trend calculation.


Regards

Jens

Trimble Terrasat
Newbie
Newbie
Posts: 16
Joined: Tue Apr 25, 2006 12:00 am

Version

Post by Trimble Terrasat » Tue Apr 21, 2009 2:10 pm

Sorry, I forgot: We have here Version 2.0.2652.22325.

But the problem also occured with the latest evaluation version.

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 Apr 21, 2009 2:26 pm

Hi Jens,

Thanks for the information. I've been able to reproduce the issue here and added it (TF02014096) to the bug list to be fixed for 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

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Thu Apr 30, 2009 10:32 am

Hi Jens,

This is an interesting problem :-)

This code works as expected:

Code: Select all

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      Steema.TeeChart.Styles.Line lineTemp = new
      Steema.TeeChart.Styles.Line(tChart1.Chart);

      lineTemp.Add(10000001, 0.1);
      lineTemp.Add(10000002, 0.2);
      lineTemp.Add(10000003, 0.3);
      lineTemp.Add(10000004, 0.4);
      lineTemp.Add(10000005, 0.5);

      Steema.TeeChart.Styles.Line line = new Steema.TeeChart.Styles.Line(tChart1.Chart);
      line.DataSource = lineTemp;

      Steema.TeeChart.Functions.TrendFunction trend = new Steema.TeeChart.Functions.TrendFunction();
      trend.PeriodAlign = Steema.TeeChart.Functions.PeriodAligns.Center;
      trend.PeriodStyle = Steema.TeeChart.Functions.PeriodStyles.NumPoints;
      trend.Period = line.Count;
      line.Function = trend;
    }
Now, adding in another significant digit to the XValues causes an incorrect chart, e.g.

Code: Select all

      lineTemp.Add(100000001, 0.1);
      lineTemp.Add(100000002, 0.2);
      lineTemp.Add(100000003, 0.3);
      lineTemp.Add(100000004, 0.4);
      lineTemp.Add(100000005, 0.5);
The two lines should coincide, but don't. Adding another significant digit to the XValues causes the chart you showed to us.

The issue here is that the size of the input values causes the internal algorithms to work at a precision beyond that of the System.Double type. The line of code that causes the issue is this one:

Code: Select all

divisor = count*sumX2-sumX*sumX;
here, sumX is the sum of all the XValues, sumX2 is the sum of all the squares of the XValues and count is the number of values in the series. So, feeding the values into this from the chart which gives us the "incorrect" values, we have:

Code: Select all

    private void InitializeOther()
    {
      double divisor, sumX2, sumX;
      int count;

      sumX2 = 5.00000003E+18;
      sumX = 5000000015.0;
      count = 5;

      divisor = count * sumX2 - sumX * sumX;
      MessageBox.Show(divisor.ToString());
    }
this calculation gives us zero, which is why the chart displays as it does. Now, one way round this problem would be to use decimals instead of doubles to perform the calculation, however, the decimal type has a low range (±1.0 x 10-28 to ±7.9 x 10+28) and the numbers we use above are already in the area of 10+20. Using decimals would therefore resolve the issue for the specific case in hand, but adding a couple more significant digits would cause the algorithm to reach the limit of decimal's range. We therefore don't see the use of decimals as a viable alternative here.

Our best suggestion, therefore, is that you factor down the input doubles to a range which causes a precise calculation. This can be done using code similar to the following:

Code: Select all

    private double factor = 0.01;

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      tChart1.GetAxisLabel += new GetAxisLabelEventHandler(tChart1_GetAxisLabel);
      Steema.TeeChart.Styles.Line lineTemp = new
      Steema.TeeChart.Styles.Line(tChart1.Chart);

      lineTemp.Add(1000000001 * factor, 0.1);
      lineTemp.Add(1000000002 * factor, 0.2);
      lineTemp.Add(1000000003 * factor, 0.3);
      lineTemp.Add(1000000004 * factor, 0.4);
      lineTemp.Add(1000000005 * factor, 0.5);

      Steema.TeeChart.Styles.Line line = new Steema.TeeChart.Styles.Line(tChart1.Chart);
      line.DataSource = lineTemp;

      Steema.TeeChart.Functions.TrendFunction trend = new Steema.TeeChart.Functions.TrendFunction();
      trend.PeriodAlign = Steema.TeeChart.Functions.PeriodAligns.Center;
      trend.PeriodStyle = Steema.TeeChart.Functions.PeriodStyles.NumPoints;
      trend.Period = line.Count;
      line.Function = trend;
    }

    void tChart1_GetAxisLabel(object sender, GetAxisLabelEventArgs e)
    {
      if (sender == tChart1.Axes.Bottom)
      {
        string text = e.LabelText;
        double d = double.Parse(text);
        d *= 1 / factor;
        e.LabelText = d.ToString(tChart1.Axes.Bottom.Labels.ValueFormat);
      }
    }
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

Trimble Terrasat
Newbie
Newbie
Posts: 16
Joined: Tue Apr 25, 2006 12:00 am

Trend Function Bug

Post by Trimble Terrasat » Wed May 06, 2009 8:16 am

Hi Christopher,

thank you very much for your reply.

For our task decimal values would solve the problem. Our values probably won't be larger than 10+22.
So I request if you can fix the bug by implementing the class with decimal variables. A solution by the mid of the year would be no problem.

For us this would be more appropriate than a solution with factors.

Best regards

Jens

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 May 06, 2009 11:29 am

Hi Jens,

Ok, I have added your request to the wish-list to be considered for inclusion 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

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Wed May 13, 2009 1:33 pm

Jens,

Ok, we've now implemented a new "UseDecimals" property (default false) into the base class of the TrendFuncion which enables code like that in the example below to run and produce a perfectly accurate chart:

Code: Select all

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      Steema.TeeChart.Styles.Line lineTemp = new
      Steema.TeeChart.Styles.Line(tChart1.Chart);

      lineTemp.Add(10000000000001, 0.1);
      lineTemp.Add(10000000000002, 0.2);
      lineTemp.Add(10000000000003, 0.3);
      lineTemp.Add(10000000000004, 0.4);
      lineTemp.Add(10000000000005, 0.5); 

      Steema.TeeChart.Styles.Line line = new Steema.TeeChart.Styles.Line(tChart1.Chart);
      line.DataSource = lineTemp;

      Steema.TeeChart.Functions.TrendFunction trend = new Steema.TeeChart.Functions.TrendFunction();
      trend.UseDecimals = true;
      trend.PeriodAlign = Steema.TeeChart.Functions.PeriodAligns.Center;
      trend.PeriodStyle = Steema.TeeChart.Functions.PeriodStyles.NumPoints;
      trend.Period = line.Count;
      line.Function = trend;
    }
This new property will be in the next version 3 maintenance release, due to be made public in the near future.
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

Post Reply