Teechartpro 7.12 Drawing a graph

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
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 Apr 27, 2009 10:15 am

Hi Didier,

For completeness, you may get this error because those variables are not initialised when the OnCalculate event is called. To solve this problem you can do something like this:

Code: Select all

procedure TForm1.TeeFunction1Calculate(Sender: TCustomTeeFunction;
  const x: Double; var y: Double);
begin
  if ((Qf<>0) and (S<>0) and (Sa<>0)) then
    y := (Qf * S * 0.36 * x) / Sa;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  Qf := 1;
  S := 8;
  Sa := 4.3;

  Series2.CheckDataSource;
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

nitin
Newbie
Newbie
Posts: 51
Joined: Thu Aug 22, 2002 4:00 am

Post by nitin » Mon Apr 27, 2009 3:25 pm

Hi Narcis,

I do this but doesn't works...

look at the code :

Code: Select all

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, TeEngine, TeeFunci, Series, ExtCtrls, TeeProcs, Chart, Math,
  StdCtrls;

type
  TForm1 = class(TForm)
    Chart1: TChart;
    Series1: TLineSeries;
    TeeFunction1: TCustomTeeFunction;
    Series2: TLineSeries;
    TeeFunction2: TCustomTeeFunction;
    procedure TeeFunction1Calculate(Sender: TCustomTeeFunction;
      const x: Double; var y: Double);
    procedure FormCreate(Sender: TObject);
    procedure TeeFunction2Calculate(Sender: TCustomTeeFunction;
      const x: Double; var y: Double);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;

var
  Form1: TForm1;
  a, b, Qf, S, Sa: Double;

implementation

{$R *.dfm}

procedure TForm1.TeeFunction1Calculate(Sender: TCustomTeeFunction;
  const x: Double; var y: Double);
begin
  y := a * power(60 * x, 1 - b); //  First function works fine
end;

procedure TForm1.TeeFunction2Calculate(Sender: TCustomTeeFunction;
  const x: Double; var y: Double);
begin
  y := (Qf * S * 0.36 * x) / Sa; // second function ?????
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  a := 28.916;
  b := 0.848;
  Qf := 1;
  S := 8;
  Sa := 4.3;
  Series1.CheckDataSource;
end;

end.
Thank you for your help

Didier

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 Apr 27, 2009 3:29 pm

Hi Didier,

At TeeFunction2Calculate you should check that those variables are not zero, as in the example I posted and then you may also need to run CheckDataSource on Series2 too.
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

nitin
Newbie
Newbie
Posts: 51
Joined: Thu Aug 22, 2002 4:00 am

Post by nitin » Tue Apr 28, 2009 3:30 pm

Thank you very much Narcis
all works fines !

Another question :
How now to show two values on each of the curves
and draw a straight line between these points ? (same x, two y different)

thank you in advance

Didier

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

Post by Yeray » Wed Apr 29, 2009 9:58 am

Hi Didier,

If I understand fine, the easiest way to do this probably would be adding a new line series with two points (one from the first function and one from the second). Here is a complete example:

Code: Select all

var a, b, Qf, S, Sa: Double;

procedure TForm1.TeeFunction1Calculate(Sender: TCustomTeeFunction;
  const x: Double; var y: Double);
begin
  y := a * power(60 * x, 1 - b);
end;

procedure TForm1.TeeFunction2Calculate(Sender: TCustomTeeFunction;
  const x: Double; var y: Double);
begin
  if ((Qf<>0) and (S<>0) and (Sa<>0)) then
    y := (Qf * S * 0.36 * x) / Sa;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D := false;

  a := 28.916;
  b := 0.848;
  Qf := 1;
  S := 8;
  Sa := 4.3;
  Series1.CheckDataSource;
  Series2.CheckDataSource;

  Series3.AddXY(Series1.XValue[5],Series1.YValue[5]);
  Series3.AddXY(Series2.XValue[25],Series2.YValue[25]);
  Series3.Pointer.Visible := true;
end;
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

Clara Genermont
Newbie
Newbie
Posts: 42
Joined: Mon Jun 11, 2007 12:00 am
Contact:

Post by Clara Genermont » Wed Apr 29, 2009 1:58 pm

Hi Narcis,

Thank you very much

We are soon at the end of the problem ..
But a small concern of conversion that I do not understand because
AddXY expected and provide double
but the message indicates an incompatibility between integer and double ..
??
Look at the code :

Code: Select all

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, TeEngine, TeeFunci, Series, ExtCtrls, TeeProcs, Chart, Math,
  StdCtrls;

type
  TForm1 = class(TForm)
    Chart1: TChart;
    Series1: TLineSeries;
    TeeFunction1: TCustomTeeFunction;
    Series2: TLineSeries;
    TeeFunction2: TCustomTeeFunction;
    Series3: TLineSeries;
    TeeFunction3: TCustomTeeFunction;
    procedure TeeFunction1Calculate(Sender: TCustomTeeFunction;
      const x: Double; var y: Double);
    procedure TeeFunction2Calculate(Sender: TCustomTeeFunction;
      const x: Double; var y: Double);
    procedure FormCreate(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;

var
  Form1: TForm1;
  a, b, Qf, S, Sa, calcul, tc,y1,y2: Double;

implementation

{$R *.dfm}

procedure TForm1.TeeFunction1Calculate(Sender: TCustomTeeFunction;
  const x: Double; var y: Double);
begin
  y := a * power(60 * x, 1 - b); //  First function
end;

procedure TForm1.TeeFunction2Calculate(Sender: TCustomTeeFunction;
  const x: Double; var y: Double);
begin
  if ((Qf <> 0) and (S <> 0) and (Sa <> 0)) then
    y := (Qf * S * 0.36 * x) / Sa; // second function
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D := false;

  a := 28.916;
  b := 0.848;
  Qf := 1;
  S := 8;
  Sa := 4.3;

 // calculate the critical value :
  tc := exp(-ln((Qf * S * 0.36) / (Sa * (1 - b) * a * power(60, 1 - b))) / b);

// determination of the Y values of the two curves to the value tc
  y1 := a * power(60 * tc, 1 - b);
  y2 := (Qf * S * 0.36 * tc) / Sa;

  Series1.CheckDataSource;
  Series2.CheckDataSource;

//  Draw a line between the two points

  Series3.AddXY(Series1.XValue[tc], Series1.YValue[y1]);   // error on this line !!!
  Series3.AddXY(Series2.XValue[tc], Series2.YValue[y2]);

  Series3.Pointer.Visible := true;
end;

end.
Thank you in advance for your help

Didier

Clara Genermont
Newbie
Newbie
Posts: 42
Joined: Mon Jun 11, 2007 12:00 am
Contact:

Post by Clara Genermont » Wed Apr 29, 2009 2:05 pm

Of course, I tried this :

Code: Select all

  Series3.AddXY(Series1.XValue[Trunc(tc)], Series1.YValue[Trunc(y1)]);   
  Series3.AddXY(Series2.XValue[Trunc(tc)], Series2.YValue[Trunc(y2)]);

But, is not good..

Didier

Clara Genermont
Newbie
Newbie
Posts: 42
Joined: Mon Jun 11, 2007 12:00 am
Contact:

Post by Clara Genermont » Wed Apr 29, 2009 2:30 pm

I think I have found :

Code: Select all

 Series3.AddXY(tc,y1);   
 Series3.AddXY(tc,y2);
have you better ?


Didier

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

Post by Yeray » Wed Apr 29, 2009 2:40 pm

Hi Didier,

1. I think that you have added a 3rd function but I think that you only need a line series.

2. You should give the X and Y points to the method Series3.AddXY. You could calculate as you are doing with tc and y1 and y2. Then, I think that this should result in the following:

Code: Select all

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, TeEngine, TeeFunci, Series, ExtCtrls, TeeProcs, Chart, Math;

type
  TForm1 = class(TForm)
    Chart1: TChart;
    Series1: TLineSeries;
    TeeFunction1: TCustomTeeFunction;
    Series2: TLineSeries;
    TeeFunction2: TCustomTeeFunction;
    Series3: TLineSeries;
    procedure TeeFunction1Calculate(Sender: TCustomTeeFunction;
      const x: Double; var y: Double);
    procedure TeeFunction2Calculate(Sender: TCustomTeeFunction;
      const x: Double; var y: Double);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  a, b, Qf, S, Sa, calcul, tc,y1,y2: Double;

implementation

{$R *.dfm}

procedure TForm1.TeeFunction1Calculate(Sender: TCustomTeeFunction;
  const x: Double; var y: Double);
begin
  y := a * power(60 * x, 1 - b); //  First function
end;

procedure TForm1.TeeFunction2Calculate(Sender: TCustomTeeFunction;
  const x: Double; var y: Double);
begin
  if ((Qf <> 0) and (S <> 0) and (Sa <> 0)) then
    y := (Qf * S * 0.36 * x) / Sa; // second function
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D := false;

  a := 28.916;
  b := 0.848;
  Qf := 1;
  S := 8;
  Sa := 4.3;

 // calculate the critical value :
  tc := exp(-ln((Qf * S * 0.36) / (Sa * (1 - b) * a * power(60, 1 - b))) / b);

// determination of the Y values of the two curves to the value tc
  y1 := a * power(60 * tc, 1 - b);
  y2 := (Qf * S * 0.36 * tc) / Sa;

  Series1.CheckDataSource;
  Series2.CheckDataSource;

//  Draw a line between the two points
  Series3.AddXY(tc, y1);
  Series3.AddXY(tc, y2);
  Series3.Pointer.Visible := true;
end;

end.
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

Clara Genermont
Newbie
Newbie
Posts: 42
Joined: Mon Jun 11, 2007 12:00 am
Contact:

Post by Clara Genermont » Mon May 04, 2009 11:47 am

Hi Yeray

thank you,

Answers were cross ..

Didier

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

Post by Yeray » Tue May 05, 2009 10:02 am

Hi Didier,

Yes, I should refresh the page before sending the message :P
I'm happy to see that works fine for you.
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