How to clear all datasources in a chart

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Errol
Newbie
Newbie
Posts: 35
Joined: Mon Jul 02, 2018 12:00 am

How to clear all datasources in a chart

Post by Errol » Sat Jul 28, 2018 1:19 am

Good afternoon
I have a reasonably complex chart, with series from a number of data sources. When I make any change to the chart, I prefer to clear all data sources and rebuild the chart using standard code. I have tried the following code:

Code: Select all

  if Chart.SeriesCount <> 0 then
  begin
    for i := 0 to Chart.SeriesCount - 1 do
      Chart.Series[i].DataSources.Clear;
  end;

However, this does not appear to work, as IDataSources.Count in VCLTee.DBChart.RefreshData keeps increasing every time I modify my chart.
To overcome this problem, I wrote a public procedure in VCLTee.DBChart as follows:

Code: Select all

procedure TCustomDBChart.ClearDataSources;
begin
  iDataSources.Clear;
end;
This works fine, and the number of datasources reported in DBChart.RefreshData correctly matches the actual number used by the chart.
Of course, a procedure in VCLTee.DBChart is not satisfactory, as I lose this on every TeeChart code upgrade. How can I permanently access this simple functionality?
Thanks and regards
Errol

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

Re: How to clear all datasources in a chart

Post by Sandra » Wed Aug 01, 2018 10:09 am

Hello Errol,

The problem you experiencing not appears for me, using DataSources.Clear in simple example with Teechart Pro VCL/FMX 2018.24. An alternative to use DataSources.Clear is, use Series Clear method. The code below shows you how:

Code: Select all

   if Chart.SeriesCount <> 0 then
  begin
    for i := 0 to Chart.SeriesCount - 1 do
      Chart.Series[i].Clear;
  end; 
Could you tell us if that works in your end? In the case the alternative solution doesn't like you, please could you send us a simple project where we can reproduce the problem you're experiencing because try to find a solution for you?

Thanks in advance
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

Errol
Newbie
Newbie
Posts: 35
Joined: Mon Jul 02, 2018 12:00 am

Re: How to clear all datasources in a chart

Post by Errol » Thu Aug 16, 2018 6:20 am

Hi Sandra
Your suggested code to clear data sources works - many thanks.
Errol

Errol
Newbie
Newbie
Posts: 35
Joined: Mon Jul 02, 2018 12:00 am

Re: How to clear all datasources in a chart

Post by Errol » Sun Aug 19, 2018 11:52 pm

Hi Sandra
On further digging, I find that the number of data sources still keeps increasing, as indicated by IDataSources.Count in procedure TCustomDBChart.RefreshData, even after using your suggested code. My graph code which I inherited is quite complex and I cannot work out why the data sources keep increasing. However, in some circumstances, this appears to cause an error.
In your next release would you be able to include a public procedure in the DBChart unit, as follows:

Code: Select all

procedure TCustomDBChart.ClearDataSources;
begin
  iDataSources.Clear;
end;
This would help matters until I can find out where the data sources are being generated.
Thanks and regards
Errol

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: How to clear all datasources in a chart

Post by Yeray » Tue Aug 21, 2018 2:08 pm

Hello Errol,

I've added it to the public tracker:
http://bugs.teechart.net/show_bug.cgi?id=2079
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply