Recent

Author Topic: [Solved] TAChart: how to reset a plot?  (Read 15991 times)

madepabloh

  • Full Member
  • ***
  • Posts: 160
[Solved] TAChart: how to reset a plot?
« on: August 24, 2011, 09:07:59 pm »
I am plotting data into a chart. I would like to reset the plot and delete the data in order to start again but without to close the program and run it again.

I tried different options:
Code: [Select]
Chart1. Series. Free;

Chart1.Series.CleanupInstance;

Chart1.CleanupInstance;

Chart1.ClearSeries;


So i am a little bit lost. Any idea about how could i do that?
Thanks!
« Last Edit: August 24, 2011, 11:46:03 pm by madepabloh »

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: TAChart: how to reset a plot?
« Reply #1 on: August 24, 2011, 11:06:56 pm »
Depends on what you want to do exactly.

I assume that your chart contains one or more series that you created at design-time and you just want to plot new data in these series. Just call the method "Clear" of each series. This erases the data from the series. Now you can add new data to the series. Unless you fixed the axis extent the axes will be updated automatically.

madepabloh

  • Full Member
  • ***
  • Posts: 160
Re: TAChart: how to reset a plot?
« Reply #2 on: August 24, 2011, 11:30:19 pm »
Exactly!!

This is what i was looking for!

I tried with Chart1.Series.Clear; but it produces error. Now, doing Clear with each serie works perfectly like this:

Code: [Select]
LineSerie1.Clear;

Thanks WP!!

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: [Solved] TAChart: how to reset a plot?
« Reply #3 on: August 25, 2011, 12:51:08 am »
The reason why Chart1.Series.Clear does not work is because the TChart property Series is an array containing all the series.

So you should call Chart1.Series[0].Clear to erase the first series, or
Code: [Select]
for i:=0 to Chart1.SeriesCount-1 do
  Chart1.Series[i].Clear;
to clear all.

In addition, each series has the name given in the Object Inspector. Therefore, you can also reference the series by this name (such as "LineSerie2").

madepabloh

  • Full Member
  • ***
  • Posts: 160
Re: [Solved] TAChart: how to reset a plot?
« Reply #4 on: August 25, 2011, 12:46:28 pm »
Thanks for the explanation... i see now what i was doing wrong...

And your code is much more simple than call one by one all the series.
Thanks wp!

jw

  • Full Member
  • ***
  • Posts: 126
Re: [Solved] TAChart: how to reset a plot?
« Reply #5 on: January 28, 2012, 03:44:03 am »
is my lazarus to old for wp's code to work?

for i:=0 to Chart.SeriesCount-1 do
         chart.Series.Clear;   
   
fails to compile  identifier ident no member clear

0.9.30
2.4.2

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: [Solved] TAChart: how to reset a plot?
« Reply #6 on: January 28, 2012, 06:56:28 am »
Hm, actually both your and his code is incorrect.
You can either use chart.Series.Clear to remove all series
(this, naturally, does not need to be in a loop)
or TChartSeries.Clear to remove all data from the specific series' source.

wp: Are you sure that the code you posted ever worked for you?
Both in trunk and 0.9.30 the Clear method is in the TChartSeries,
not in TBasicChartSeries, so a cast is required.

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: [Solved] TAChart: how to reset a plot?
« Reply #7 on: January 28, 2012, 09:26:06 am »
Oh, you are right in both cases -- I was not aware of the Clear method of the TChartSeriesList

jw

  • Full Member
  • ***
  • Posts: 126
Re: [Solved] TAChart: how to reset a plot?
« Reply #8 on: January 29, 2012, 06:45:00 pm »
tchartseries.clear works to clear a single series one by one, but chart.series.clear does nothing.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: [Solved] TAChart: how to reset a plot?
« Reply #9 on: January 29, 2012, 07:13:09 pm »
chart.series.clear does nothing.

It does remove all series, but does not refresh the chart --
which I have fixed in r34981.

You can either back-port the fix to your local copy or refresh the chart manually.

jw

  • Full Member
  • ***
  • Posts: 126
Re: [Solved] TAChart: how to reset a plot?
« Reply #10 on: January 30, 2012, 12:41:30 am »
I can't find the package in the svn
https://lazarus-ccr.svn.sourceforge.net/svnroot/lazarus-ccr/components/

is it easiest to just download the latest a daily snapshot?

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: [Solved] TAChart: how to reset a plot?
« Reply #11 on: January 30, 2012, 04:23:05 am »
Yes. TAChart package is part of the Lazarus repository.

 

TinyPortal © 2005-2018