Series.Assign and Series.AssignValues problem

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Uli
Newbie
Newbie
Posts: 80
Joined: Thu Apr 22, 2010 12:00 am

Series.Assign and Series.AssignValues problem

Post by Uli » Sat May 29, 2010 6:57 am

Hallo,

I need the possibility to copy series from one chart to another. I tried it first with the series clone method but this did not work sufficiently. So I did it bythis code:

Code: Select all

   Public Overridable Sub CopySeries(ByVal Src As Series, ByVal SrcChart As TChart, ByVal DestChart As TChart, ByVal CopyDataPoints As Boolean)
        Try
            'MyMainForm1.CopiedSeries is a buffer for some copy/paste actions            
            If MyMainForm1.CopiedSeries IsNot Nothing Then MyMainForm1.CopiedSeries.Dispose()
            If TypeOf Src Is FastLine Then MyMainForm1.CopiedSeries = New Steema.TeeChart.Styles.FastLine()
            If TypeOf Src Is Line Then MyMainForm1.CopiedSeries = New Steema.TeeChart.Styles.Line()
            If TypeOf Src Is Points Then MyMainForm1.CopiedSeries = New Steema.TeeChart.Styles.Points()
            If CopyDataPoints Then
                MyMainForm1.CopiedSeries.AssignValues(Src)
                MyMainForm1.CopiedSeries.Assign(Src)
                MyMainForm1.CopiedSeries.AssignFormat(Src)
                MyMainForm1.CopiedSeries.Tag = Src.Tag
                MyMainForm1.CopiedSeries.Title = MyMainForm1.CopiedSeries.Title
            End If
            If TypeOf Src Is Line Then
               'This was necessary since for line series the data point properties were not copied - a bug, I assume...
                Dim Line1 As Line = MyMainForm1.CopiedSeries
                Dim Line2 As Line = Src
                Line1.Pointer = Line2.Pointer
            End If
            If DestChart IsNot Nothing Then
                DestChart.Series.Add(MyMainForm1.CopiedSeries)
                MyMainForm1.CopiedSeries = Nothing
            End If
        Catch ex As Exception
            MsgBox("CopySeries: " + Chr(13) + ex.Message)
        End Try
This code was previously created with the Teechart for VS 2009 edition and tested mainly with Line Series. Now I work with the Techart for VS 2010 edition and due to the bug [TF02014877] mainly with fastline series.

The problem is with the following lines:

Code: Select all

                'concrete example: Src has 111 data points
                'Before executing one of the following lines
                'MyMainForm1.CopiedSeries.YValues.Value() has the length of 111
                MyMainForm1.CopiedSeries.AssignValues(Src)
                MyMainForm1.CopiedSeries.Assign(Src)
                'Now MyMainForm1.CopiedSeries.YValues.Value() has the length of 126
                'MyMainForm1.CopiedSeries.YValues.count is still 111

The new data points are at the end of the .Value() and are all (0,0). At a first glance they seem to be "invisible" but they are not invisible. For a mathematical procedure I use a method from DSP Signal (DewResearch):

Code: Select all

            Dim XValues As Vector
            Dim YValues As Vector
            YValues.CopyFromArray(SourceChart.Series(cbSeries.SelectedIndex).YValues.Value)
            XValues.CopyFromArray(SourceChart.Series(cbSeries.SelectedIndex).XValues.Value)
And now all the 126 points are in the vectors. Strange!

That implies that accessing the data points as array (of double, for instance) is impossible since one can not trust that the values() property always returns the true data points...

Best regards

Uli

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Series.Assign and Series.AssignValues problem

Post by Narcís » Tue Jun 01, 2010 1:44 pm

Hi Uli,

Could you please attach a simple example project we can run "as-is" to reproduce the problem here?

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

Uli
Newbie
Newbie
Posts: 80
Joined: Thu Apr 22, 2010 12:00 am

Re: Series.Assign and Series.AssignValues problem

Post by Uli » Wed Jun 02, 2010 6:14 am

Hi Narcis,

place a Teechart and two buttons on the form:

Code: Select all

    Dim fl1 As FastLine = Nothing
    Dim fl2 As FastLine = Nothing
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If fl1 IsNot Nothing Then fl1.Clear()
        If fl2 IsNot Nothing Then
            fl2.Dispose()
            fl2 = New FastLine
        End If
        If fl1 Is Nothing Then fl1 = New FastLine(Chart1.Chart)
        If fl2 Is Nothing Then fl2 = New FastLine
        fl1.FillSampleValues(110)
        Chart1.Invalidate()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        fl2.AssignValues(fl1)
        fl2.Assign(fl1)
        fl2.AssignFormat(fl1)
        MsgBox(fl2.XValues.Value.Length) '--> "126"
        Chart1.Invalidate()
    End Sub
You can see the things in the debugger, too.

BTW, previously another bug encountered. Put a chartcontroller to the form and connect it with the chart. Here is the modified code:

Code: Select all

    Dim fl1 As FastLine = Nothing
    Dim fl2 As FastLine = Nothing
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If fl1 Is Nothing Then fl1 = New FastLine(Chart1.Chart)
        If fl2 Is Nothing Then fl2 = New FastLine(Chart1.Chart)
        fl1.FillSampleValues(110)
        fl2.FillSampleValues(100)
        Chart1.Invalidate()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        fl1.Delete(0, 10)
    End Sub
Now execute the chart editor, chose on the series tab fastline1, then click the data tab: The deleted points are still there.

Regards

Uli

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Series.Assign and Series.AssignValues problem

Post by Narcís » Thu Jun 03, 2010 1:08 pm

Hi Uli,
You can see the things in the debugger, too.
Ok, but if you use fl2.XValues.Count you already have 110 points. Does this solve the problem for you?
Now execute the chart editor, chose on the series tab fastline1, then click the data tab: The deleted points are still there.
This works fine for me here using latest TeeChart for .NET 2010 release available as you can see here:
DeletedPoints.png
DeletedPoints.png (9.86 KiB) Viewed 16857 times
Which TeeChart version are you using?
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

Uli
Newbie
Newbie
Posts: 80
Joined: Thu Apr 22, 2010 12:00 am

Re: Series.Assign and Series.AssignValues problem

Post by Uli » Thu Jun 03, 2010 1:34 pm

Hi Narcis,

thanks.
Ok, but if you use fl2.XValues.Count you already have 110 points. Does this solve the problem for you?
No. As I wrote in my initial message I have to copy the data values to an vector. And the method of the vector adds also these "ghost" points. Of course, I could add the regular points by iterating the value lists but it requires more time, especially in the case of big series. Generally, it means, one can never work with methods which accept arrays as parameter. So I think it's a bug that should be fixed.
Which TeeChart version are you using?
TeeChart for .NET 2010. I have to say that I could not reproduce the behavior right now. Mysterious.

Regards,

Uli

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Series.Assign and Series.AssignValues problem

Post by Narcís » Thu Jun 03, 2010 1:46 pm

H Uli,

Ok, I see directly copying ValueLists arrays doesn't work either:

Code: Select all

            fl2.XValues.Count = fl1.XValues.Count
            fl2.XValues.Value = fl1.XValues.Value

            fl2.YValues.Count = fl1.YValues.Count
            fl2.YValues.Value = fl1.YValues.Value
So I have added the issue (TF02014933) to the bug list to be fixed for future releases.
TeeChart for .NET 2010. I have to say that I could not reproduce the behavior right now. Mysterious.
If you find a consistent way to reproduce the issue please let us know.

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

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Series.Assign and Series.AssignValues problem

Post by Narcís » Mon Jun 14, 2010 11:01 am

Hi Uli,

We have been investigating TF02014933 further and we reached the conclusion it is not a bug. If you want to know how many points are in a series, as I told you before, you should use ValueList.Count and not the length of ValueList.Value as it is never going to represent the number of points in the series. That's what the Count property is for.

A solution to not having to iterate through the arrays is using Array.Copy in a similar manner to Add(Array xValues, Array yValues, bool append) method. For example:

Code: Select all

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

    Steema.TeeChart.Styles.FastLine fl1 = null;
    Steema.TeeChart.Styles.FastLine fl2 = null;

    private void InitializeChart()
    {
      fl1 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
      fl2 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);

      fl1.FillSampleValues(110);

      tChart1.Click += new EventHandler(tChart1_Click);
    }

    void tChart1_Click(object sender, EventArgs e)
    {
      double[] tmpX = new double[fl1.XValues.Count];
      double[] tmpY = new double[fl1.YValues.Count];

      Array.Copy(fl1.XValues.Value, 0, tmpX, 0, fl1.XValues.Count);
      Array.Copy(fl1.YValues.Value, 0, tmpY, 0, fl1.YValues.Count);

      fl2.XValues.Count = fl1.XValues.Count;
      fl2.XValues.Value = tmpX;

      fl2.YValues.Count = fl1.YValues.Count;
      fl2.YValues.Value = tmpY;

      fl2.Repaint();

      MessageBox.Show(fl2.XValues.Value.Count().ToString());
    }
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

Uli
Newbie
Newbie
Posts: 80
Joined: Thu Apr 22, 2010 12:00 am

Re: Series.Assign and Series.AssignValues problem

Post by Uli » Wed Jun 16, 2010 12:38 pm

Hi Narcis,

this I copied from the TeeChart help:
The Assign method copies all properties from a Series component to another.
Only the common properties shared by both source and destination Series are copied.
Following this, I would expect that both series show same properties. This is not the case. So I would still assume this behavior as a bug.

Best regards

Uli

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

Re: Series.Assign and Series.AssignValues problem

Post by Sandra » Thu Jun 17, 2010 11:48 am

Hello Uli,

Using next code and last version of TeeChart.Net, Assign method works as expected . Could you please explain us exactly, because you consider that method Assign don't works fine for you?

Code: Select all

        private Steema.TeeChart.Styles.FastLine fl1, fl2;
        private void InitializeChart()
        {
            fl1 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
            fl2 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
            fl1.FillSampleValues();
        }

        void button2_Click(object sender, System.EventArgs e)
        {
            fl2.Assign(fl1);
            MessageBox.Show(fl2.XValues.Value.Length.ToString());
        }
Could you please modify the example code so that we can reproduce the issue 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

Uli
Newbie
Newbie
Posts: 80
Joined: Thu Apr 22, 2010 12:00 am

Re: Series.Assign and Series.AssignValues problem

Post by Uli » Fri Jun 18, 2010 6:27 am

Hi Sandra,

I use TeeChart for .net 2010 (Release from end of April). I do not know about a newer one and so I think it's the newest one.

If you will execute the code in my post from Wed Jun 02, 2010 6:14 am, first eaxample, you can see the strange behavior by monitoring (Watch) the .XValues.Value.Length values.
I think, Narcis has realized that. He pointed to methods to overcome this problem, OK. But this requires additional code and time at run time. And it's not the behavior one could expect: After assigning values to a new series should be:
newseries.XValues.Value.Length = oldseries.XValues.Value.Length
And this is not the case. Some time later I may have forgotten this strange behavior and could run again in this pitfall. Other users possibly, too. So I still think it's a bug.

Best regards

Uli

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Series.Assign and Series.AssignValues problem

Post by Narcís » Fri Jun 18, 2010 8:34 am

Hello Uli,

As I told you in my 14th June reply:
Narcís wrote:If you want to know how many points are in a series, as I told you before, you should use ValueList.Count and not the length of ValueList.Value as it is never going to represent the number of points in the series. That's what the Count property is for.
This means that code below, which only uses Series.Assign(Series) works fine. Can you please check if it works fine for you?

Code: Select all

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

    Steema.TeeChart.Styles.FastLine fl1 = null;
    Steema.TeeChart.Styles.FastLine fl2 = null;

    private void InitializeChart()
    {
      fl1 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
      fl2 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);

      fl1.FillSampleValues(110);

      tChart1.Click += new EventHandler(tChart1_Click);
    }

    void tChart1_Click(object sender, EventArgs e)
    {
      fl2.Assign(fl1);

      int numXValues = fl2.XValues.Count;
      int numYValues = fl2.YValues.Count;

      MessageBox.Show(numXValues.ToString());
      MessageBox.Show(numYValues.ToString());
    }
Having said that, we don't consider this issue a bug any more. However if you still think that Assign method is not correctly assigning any other series property don't hesitate to let us know.

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

Uli
Newbie
Newbie
Posts: 80
Joined: Thu Apr 22, 2010 12:00 am

Re: Series.Assign and Series.AssignValues problem

Post by Uli » Fri Jun 18, 2010 10:54 am

Hi Narcis,

it's not only a question of getting the correct point count. As I wrote in my message from Thu Jun 03, 2010 1:34 pm I have to copy the XValues to a Vector. This should be done by a DewMath function (I purchased TeeChart bundled with the DewLab libraries). And even when I set the vector length before copying the .Value array to the vector the vector got all points, including the ghost points. Therefore, iteration through all the data values to add them to the vector (or an intermediate array as you suggested in your last post) is required. These are only workarounds but need additional run time and additional code.

I accept, that you do not further assume this strange behavior as a bug but please understand that I still do so: Who can guarantee that in a further calculation within the highly complex TChart object it does not internally use the .Value property in a way leading to errors? It's a question of confidence, too.

Best regards

Uli

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Series.Assign and Series.AssignValues problem

Post by Narcís » Fri Jun 18, 2010 3:12 pm

Hi Uli,

Which is the signature of the DewMath function you need to use? Or how do you need to use it exactly? And which is the problem of using a temporary array?
Who can guarantee that in a further calculation within the highly complex TChart object it does not internally use the .Value property in a way leading to errors? It's a question of confidence, too.
TeeChart has been like this for 15 years and we are not aware of any problem in this area for now.

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

Uli
Newbie
Newbie
Posts: 80
Joined: Thu Apr 22, 2010 12:00 am

Re: Series.Assign and Series.AssignValues problem

Post by Uli » Mon Jun 21, 2010 8:35 am

Hi Narcis,

the following code was used to copy the values to the Vector:

Code: Select all

                    Private Sub ReadSpectrum(ByVal title As String, ByRef vec As Vector, ByRef FirstSpctrumIndex As Integer)
                    ...
                    vec.Size(series.YValues.Count)
                    vec.CopyFromArray(series.YValues.Value)
                    ...
So the error is additionally surprizing since with the first code line the vector size was explicitely set. A temporary array makes code bigger and introduces error possibilities when I change the code wherever I use the .Value array... And requires some additional work: I just found 14 deposits of this vec.CopyFromArray method using the .Value array.
Who can guarantee that in a further calculation within the highly complex TChart object it does not internally use the .Value property in a way leading to errors? It's a question of confidence, too.
TeeChart has been like this for 15 years and we are not aware of any problem in this area for now.
Some problems may only arise under special circumstances...

You know, even the biggest software companies do not claim that their programs are free of errors. But I think they would be willing to fix them as they realize such things.

Best regards

Uli

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

Re: Series.Assign and Series.AssignValues problem

Post by Sandra » Mon Jun 21, 2010 10:40 am

Hi Uli,

Thanks for the info. We could reproduce the problem here using Dew.Math.Vector. However, we solved it using a different override of CopyFromArray as you can see in the code snippet below. Can you please check if this works fine for you?
wherever I use the .Value array... And requires some additional work: I just found 14 deposits of this vec.CopyFromArray method using the .Value array.

Code: Select all

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

        Steema.TeeChart.Styles.FastLine fl1 = null;
        Steema.TeeChart.Styles.FastLine fl2 = null;

        private void InitializeChart()
        {
            fl1 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
            fl2 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);            

            fl1.FillSampleValues(110);
            tChart1.Click += new EventHandler(tChart1_Click);
        }

        void tChart1_Click(object sender, EventArgs e)
        {
            fl2.Assign(fl1);
          
            int numXValues = fl2.XValues.Count;
            int numYValues = fl2.YValues.Count;

            Dew.Math.Vector vect = new Dew.Math.Vector();
            vect.Size(fl1.YValues.Count);
            vect.CopyFromArray(fl1.YValues.Value, 0, 0, fl1.YValues.Count);

            MessageBox.Show("Series size: " + numXValues.ToString());
            MessageBox.Show("Vector size: " + vect.Length.ToString());
        }
Some problems may only arise under special circumstances...

You know, even the biggest software companies do not claim that their programs are free of errors. But I think they would be willing to fix them as they realize such things.
Of course, it would be stupid and arrogant from our side claiming our software is bug free. However, to be able to address issues we need to be able to know the exact circumstances in which they occur and reproduce them here.
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

Post Reply