Page 1 of 1

How to clear all datasources in a chart

Posted: Sat Jul 28, 2018 1:19 am
by 16583932
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

Re: How to clear all datasources in a chart

Posted: Wed Aug 01, 2018 10:09 am
by 10050769
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

Re: How to clear all datasources in a chart

Posted: Thu Aug 16, 2018 6:20 am
by 16583932
Hi Sandra
Your suggested code to clear data sources works - many thanks.
Errol

Re: How to clear all datasources in a chart

Posted: Sun Aug 19, 2018 11:52 pm
by 16583932
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

Re: How to clear all datasources in a chart

Posted: Tue Aug 21, 2018 2:08 pm
by yeray
Hello Errol,

I've added it to the public tracker:
http://bugs.teechart.net/show_bug.cgi?id=2079