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

  1. unit Function_AverageNulls;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   Base, StdCtrls, TeEngine, TeeFunci, Series, ExtCtrls, TeeProcs, Chart;
  8.  
  9. type
  10.   TAverageFunctionNulls = class(TBaseForm)
  11.     CheckBox1: TCheckBox;
  12.     Series1: TBarSeries;
  13.     Series2: TLineSeries;
  14.     TeeFunction1: TAverageTeeFunction;
  15.     Label1: TLabel;
  16.     LabelAverage: TLabel;
  17.     procedure CheckBox1Click(Sender: TObject);
  18.     procedure FormCreate(Sender: TObject);
  19.   private
  20.     { Private declarations }
  21.     Procedure SetLabelAverage;
  22.   public
  23.     { Public declarations }
  24.   end;
  25.  
  26. implementation
  27.  
  28. {$R *.DFM}
  29.  
  30. procedure TAverageFunctionNulls.CheckBox1Click(Sender: TObject);
  31. begin
  32.   TeeFunction1.IncludeNulls:=CheckBox1.Checked;
  33.  
  34.   SetLabelAverage;
  35. end;
  36.  
  37. Procedure TAverageFunctionNulls.SetLabelAverage;
  38. var tmp      : Double;
  39.     t        : Integer;
  40.     tmpCount : Integer;
  41. begin
  42.   { calculate the sum and number of points... }
  43.   tmp:=0;
  44.   tmpCount:=0;
  45.   for t:=0 to Series1.Count-1 do
  46.   begin
  47.     { consider or not null points... }
  48.     if TeeFunction1.IncludeNulls or (not Series1.IsNull(t)) then
  49.     begin
  50.       tmp:=tmp+Series1.YValues[t];
  51.       Inc(tmpCount);
  52.     end;
  53.   end;
  54.  
  55.   LabelAverage.Caption:=FloatToStr(tmp)+' / '+
  56.                         IntToStr(tmpCount)+' = '+
  57.                         FloatToStr(tmp/tmpCount);
  58. end;
  59.  
  60. procedure TAverageFunctionNulls.FormCreate(Sender: TObject);
  61. begin
  62.   inherited;
  63.  
  64.   { Add some points and one null point... }
  65.  
  66.   Series1.Clear;
  67.   Series1.Add( 10 ,'One', clRed );
  68.   Series1.Add( 20 ,'Two', clRed );
  69.   Series1.AddNull('Three');
  70.   Series1.Add( 40 ,'Four', clRed );
  71.   Series1.Add( 50 ,'Five', clRed );
  72.  
  73.   Series1.Marks.Style:=smsValue;
  74.  
  75.   SetLabelAverage;
  76. end;
  77.  
  78. initialization
  79.   RegisterClass( TAverageFunctionNulls );
  80. end.
  81.