home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Delphi1_And_Delphi2 / EXAMPLES / EXTENDED / UFITAXIS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  2.4 KB  |  100 lines

  1. {*********************************************}
  2. {  TeeChart Pro 4 example                     }
  3. {  Copyright (c) 1995-1998 by David Berneda   }
  4. {  All rights reserved                        }
  5. {*********************************************}
  6. unit Ufitaxis;
  7.  
  8. interface
  9.  
  10. { This example resets the Axis scales to the minimum and
  11.   maximum values of Series points in a single page.
  12.  
  13.   By default, the minimum and maximum are calculated using
  14.   ALL pages.
  15.   This example shows how to fit points in a single page.
  16. }
  17. uses
  18.   WinTypes,WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  19.   TeEngine, Series, ExtCtrls, TeeProcs, Chart, StdCtrls;
  20.  
  21. type
  22.   TFormFitAxis = class(TForm)
  23.     Chart1: TChart;
  24.     Series1: TBarSeries;
  25.     Button1: TButton;
  26.     Button2: TButton;
  27.     Button3: TButton;
  28.     Button4: TButton;
  29.     procedure FormCreate(Sender: TObject);
  30.     procedure Button2Click(Sender: TObject);
  31.     procedure Button1Click(Sender: TObject);
  32.     procedure Button3Click(Sender: TObject);
  33.     procedure Button4Click(Sender: TObject);
  34.     procedure Chart1PageChange(Sender: TObject);
  35.   private
  36.     { Private declarations }
  37.   public
  38.     { Public declarations }
  39.     Procedure CalcAxis;
  40.   end;
  41.  
  42. var
  43.   FormFitAxis: TFormFitAxis;
  44.  
  45. implementation
  46.  
  47. {$R *.DFM}
  48.  
  49. procedure TFormFitAxis.FormCreate(Sender: TObject);
  50. begin
  51.   Series1.FillSampleValues(80); { sample values }
  52. end;
  53.  
  54. { calculate the minimum and maximum  }
  55. Procedure TFormFitAxis.CalcAxis;
  56. var t:Integer;
  57.     tmp,tmpMin,tmpMax:Double;
  58. begin
  59.   tmpMin:=0;
  60.   tmpMax:=0;
  61.   { loop of visible points in current page... }
  62.   for t:=Series1.FirstValueIndex to Series1.LastValueIndex do
  63.   begin
  64.     tmp:=Series1.YValues[t];
  65.     if tmp<tmpMin then tmpMin:=tmp;  { calculate minimum }
  66.     if tmp>tmpMax then tmpMax:=tmp;  { calculate maximum }
  67.   end;
  68.   Series1.GetVertAxis.SetMinMax(tmpMin,tmpMax); { set axis scales }
  69. end;
  70.  
  71. procedure TFormFitAxis.Button2Click(Sender: TObject);
  72. begin
  73.   Chart1.NextPage;
  74. end;
  75.  
  76. procedure TFormFitAxis.Button1Click(Sender: TObject);
  77. begin
  78.   Chart1.PreviousPage;
  79. end;
  80.  
  81. procedure TFormFitAxis.Button3Click(Sender: TObject);
  82. begin
  83.   CalcAxis;
  84. end;
  85.  
  86. procedure TFormFitAxis.Button4Click(Sender: TObject);
  87. begin
  88.   Close;
  89. end;
  90.  
  91. procedure TFormFitAxis.Chart1PageChange(Sender: TObject);
  92. begin
  93.   Chart1.LeftAxis.AdjustMaxMin;
  94.   Chart1.BottomAxis.AdjustMaxMin;
  95.   Series1.CalcFirstLastVisibleIndex;
  96.   CalcAxis;
  97. end;
  98.  
  99. end.
  100.