home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Delphi / TeeChartPro / TeeChart5Delphi5Eval.exe / %MAINDIR% / Examples / Features / CurveFitting_Coef.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-09-10  |  2.0 KB  |  87 lines

  1. unit CurveFitting_Coef;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   Base, StdCtrls, TeEngine, CurvFitt, Series, ExtCtrls, TeeProcs, Chart,
  8.   TeeShape, TeeTools;
  9.  
  10. type
  11.   TCurveFittingCoef = class(TBaseForm)
  12.     Series1: TFastLineSeries;
  13.     TeeFunction1: TCurveFittingFunction;
  14.     Series2: TFastLineSeries;
  15.     Label1: TLabel;
  16.     Label2: TLabel;
  17.     Series3: TChartShape;
  18.     ChartTool1: TMarksTipTool;
  19.     procedure FormCreate(Sender: TObject);
  20.     procedure Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  21.       Y: Integer);
  22.   private
  23.     { Private declarations }
  24.     Procedure ShowFunction;
  25.   public
  26.     { Public declarations }
  27.   end;
  28.  
  29. implementation
  30.  
  31. {$R *.DFM}
  32.  
  33. procedure TCurveFittingCoef.FormCreate(Sender: TObject);
  34. begin
  35.   inherited;
  36.   Series1.FillSampleValues(100);
  37.  
  38.   { set the "shape" xy as pixels... }
  39.   Series3.XYStyle:=xysPixels;
  40.  
  41.   { show the polynomy... }
  42.   ShowFunction;
  43. end;
  44.  
  45. Procedure TCurveFittingCoef.ShowFunction;
  46. var t   : Integer;
  47.     tmp : String;
  48. begin
  49.   tmp:='y=';
  50.   With TeeFunction1 do
  51.   for t:=1 to PolyDegree do
  52.   begin
  53.     tmp:=tmp+' ';
  54.     if AnswerVector[t]>=0 then tmp:=tmp+'+';
  55.     tmp:=tmp+FormatFloat('0.0##',AnswerVector[t])+'*x';
  56.     if t>1 then tmp:=tmp+'^'+IntToStr(t);
  57.   end;
  58.  
  59.   { show the expression }
  60.   Label2.Caption:=tmp;
  61. end;
  62.  
  63. procedure TCurveFittingCoef.Chart1MouseMove(Sender: TObject;
  64.   Shift: TShiftState; X, Y: Integer);
  65. var tmpX,tmpY : Double;
  66. begin
  67.   { convert from "X" pixels to axis... }
  68.   tmpX:=Chart1.BottomAxis.CalcPosPoint(X);
  69.  
  70.   { calculate the "Y" value for a given "X" }
  71.   tmpY:=TeeFunction1.GetCurveYValue(Series1,tmpX);
  72.  
  73.   { convert from "Y" axis to pixels... }
  74.   Y:=Chart1.LeftAxis.CalcPosValue(tmpY);
  75.  
  76.   { set the "circle shape" bounds... }
  77.   Series3.X0:=X-10;
  78.   Series3.X1:=X+10;
  79.   Series3.Y0:=Y-10;
  80.   Series3.Y1:=Y+10;
  81.   Series3.Active:=True;
  82. end;
  83.  
  84. initialization
  85.   RegisterClass(TCurveFittingCoef);
  86. end.
  87.