Function series management

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
quickweb
Newbie
Newbie
Posts: 13
Joined: Mon Apr 16, 2007 12:00 am
Contact:

Function series management

Post by quickweb » Fri May 11, 2007 8:42 am

Hello,

I want to know if there is a way of tracking down the series related to a
certain function I have defined at runtime.

For example, suppose I need to add and then remove a Bollinger Bands
function. Adding it is easy, but this function would generate two
additional line series to my chart. At a later point I would need to
remove it from the chart along with the corresponding line series. How can
I identify which series are related to a particular instance of Bollinger
Bands function?

I know the chart can do that, as when I look at a series it shows what
function, along with proper parameters represents the model for it. How
can I do that in code? There is nothing like "GetFunction" method as it
with "SetFunction" for a series...

Thank you,
Cristina

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

Post by Narcís » Fri May 11, 2007 9:48 am

Hi Cristina,

As internal series are not shown in the legend and easy way to achieve what you request would be doing something like this:

Code: Select all

uses Series, StatChar;

procedure TForm1.FormCreate(Sender: TObject);
var tmpBarSeries1,tmpBarSeries2:TBarSeries;
    tmpLineSeries:TLineSeries;
begin
  With Chart1 do
  begin
    //Add 2 data Series
    tmpBarSeries1:=TBarSeries.Create(self);
    tmpBarSeries2:=TBarSeries.Create(self);
    AddSeries(tmpBarSeries1);
    AddSeries(tmpBarSeries2);
    //Populate them with data (here random)
    tmpBarSeries1.FillSampleValues(10);
    tmpBarSeries2.FillSampleValues(10);
    //Add a series to be used for an Average Function
    tmpLineSeries:=TLineSeries.Create(self);
    AddSeries(tmpLineSeries);
    //Define the Function Type for the new Series
    tmpLineSeries.SetFunction(TBollingerFunction.Create(self));
    //Define the Datasource for the new Function Series
    //Datasource accepts the Series titles of the other 2 Series
    tmpLineSeries.DataSources.Clear;
    tmpLineSeries.DataSources.Add( tmpBarSeries1 );
    tmpLineSeries.DataSources.Add( tmpBarSeries2 );
    //    *Note - When populating your input Series manually you will need to
     //    use the Checkdatasource method
     //    - See the section entitled 'Defining a Datasource'
    //Change the Period of the Function so that it groups averages
    //every 2 Points
    tmpLineSeries.FunctionType.Period := 2;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var i: Integer;
begin
  for i:=Chart1.SeriesCount-1 downto 0 do
    if ((Chart1[i].FunctionType is TBollingerFunction) or
        not (Chart1[i].ShowInLegend))then
      Chart1.RemoveSeries(i);
end;
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

quickweb
Newbie
Newbie
Posts: 13
Joined: Mon Apr 16, 2007 12:00 am
Contact:

Post by quickweb » Sat May 19, 2007 8:21 pm

Hello,
procedure TForm1.Button1Click(Sender: TObject);
var i: Integer;
begin
for i:=Chart1.SeriesCount-1 downto 0 do
if ((Chart1.FunctionType is TBollingerFunction) or
not (Chart1.ShowInLegend))then
Chart1.RemoveSeries(i);
end;

This is not working. I've tried like that (my code is in Borland C++ and I transformed it in Delphi, hereunder) :
procedure TForm1.Button1Click(Sender: TObject);
var i: Integer;
begin
for i:=Chart1.Series.Count-1 downto 0 do
if (Chart1.Series.ShowInLegend) then
Chart1.RemoveSeries(i);
end;

I observed I didn't get Chart1.Series.ShowInLegend = false and in series.count it is not included the second series.

You can give me examples in Delphi because I know Delphi, too.

Please advice.
Thank you,
Cristina

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

Post by Narcís » Mon May 21, 2007 7:45 am

Hello Christina,
This is not working. I've tried like that (my code is in Borland C++ and I transformed it in Delphi, hereunder) :
procedure TForm1.Button1Click(Sender: TObject);
var i: Integer;
begin
for i:=Chart1.Series.Count-1 downto 0 do
if (Chart1.Series.ShowInLegend) then
Chart1.RemoveSeries(i);
end;

I observed I didn't get Chart1.Series.ShowInLegend = false and in series.count it is not included the second series.


I guess you missed the not in the if statement as I posted. However, the code I posted works fine for me here. If the problem persists could you please send us a simple example project we can run "as-is" to reproduce the problem here and let us know which TeeChart version are you using?

You can post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.
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

quickweb
Newbie
Newbie
Posts: 13
Joined: Mon Apr 16, 2007 12:00 am
Contact:

Post by quickweb » Mon May 21, 2007 9:16 am

Hello,
Sorry,
In fact I assumed that the type for internal series is TLineSeries. It seems do not be. I had another such of condition above and this was the reason.

Thank you,
Cristina

Post Reply