Recent

Author Topic: tlineseries.clear method when changing array size  (Read 4655 times)

jkorten

  • New Member
  • *
  • Posts: 20
tlineseries.clear method when changing array size
« on: July 11, 2012, 04:59:23 pm »
Hello everyone. I'm a happy new user of tachart. Have a question about clearing the line series.

I use a tlineseries associated with a tchart (simple x,y plotting) and when I change the array size from say 4096 to 2048, even though I call the clear function, the leftover data from the previous plot appears on the chart.

How can I reset the extent of the line series? (I assume the first time I load up the tlineseries with an array, the object now assumes there are that many elements always in the tlineseries.)

Many thanks for your help in advance.

Jerry

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: tlineseries.clear method when changing array size
« Reply #1 on: July 11, 2012, 09:18:42 pm »
Quote
I use a tlineseries associated with a tchart (simple x,y plotting) and when I change the array size from say 4096 to 2048, even though I call the clear function, the leftover data from the previous plot appears on the chart.

How do you connect the series to the array? Do you use user-defined source?
Please describe what you are doing in more detail or post a relevant part of your code.

jkorten

  • New Member
  • *
  • Posts: 20
Re: tlineseries.clear method when changing array size
« Reply #2 on: July 11, 2012, 11:15:20 pm »
I double clicked on the tchart object and added a line series. Then when I want to update the series I execute the following code...

form1.psd_data_series.Clear;
  form1.psd_data_series.BeginUpdate;

  with form1.psd_chart do
  begin
    if psd_smoothing then
    begin
      for i := 1 to (m div 2) do
        form1.psd_data_series.addxy(freq'['i']', smth'['i']')
    end
    else
      for i := 1 to (m div 2) do
        form1.psd_data_series.AddXY(freq'['i']', amp'['i']');
  end;
  form1.psd_data_series.EndUpdate;
  form1.psd_chart.Invalidate;

However, if I change (to a lower number) the number of points I am putting into the line series (m) then execute the above code, there is garbage left from the previous array.

(Sorry I quoted the array brackets as it screwed up the html)
« Last Edit: July 11, 2012, 11:17:48 pm by jkorten »

wp

  • Hero Member
  • *****
  • Posts: 7332
Re: tlineseries.clear method when changing array size
« Reply #3 on: July 11, 2012, 11:51:16 pm »
In the attached demo the number of points and the range of the data is varied with each click on the button. As you can see the chart perfectly adapts to each data set.

Did you modify the chart's extent? For automatic scaling it is important to have the properties UseXMin, UseXMax, UseYMin and UseYMay of Chart.Extent at false.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

jkorten

  • New Member
  • *
  • Posts: 20
Re: tlineseries.clear method when changing array size
« Reply #4 on: July 12, 2012, 12:54:01 am »
Strange - I have to remove the line

  RequireDerivedFormResource := True;

in order for your demo to compile. I've tried setting the extent properties as suggested but no joy.

I will have to delete the tchart object and drop a new one in and see if any property was inadvertently set.

I can set all my Y values to 0, but when I change from 4096 pairs to 2048 pairs you see the line go back in the x direction and swipe zeros across the bottom.

I'm assuming this array size is certainly within limits.

I'll try looking at the getxmax etc first and report back on what I find.

Thank you very much for your help!




wp

  • Hero Member
  • *****
  • Posts: 7332
Re: tlineseries.clear method when changing array size
« Reply #5 on: July 12, 2012, 09:04:41 am »
It seems that you have an old version of Lazarus. Remove the BeginUpdate and EndUpdate calls from your code - if I remember correctly a missing update of the chart's extent in EndUpdate had been fixed by Ask recently. Alternatively, try one of the daily snapshots.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

jkorten

  • New Member
  • *
  • Posts: 20
Re: tlineseries.clear method when changing array size
« Reply #6 on: July 12, 2012, 03:16:11 pm »
 :-[

Removed beginupdate and endupdate and window refreshes well now. (I am using 0.9.30.4 so still unclear about the requirederivedfromsource statement - but I will deal with this later).

Array filling was in error - hence the previous data appearing.

Who would have thought I'd had a math error in there?

All working well now. Thanks!


 

TinyPortal © 2005-2018