home *** CD-ROM | disk | FTP | other *** search
- unit UISOAxis;
-
- interface
-
- uses
- WinTypes,WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, Buttons, TeEngine, Series, ExtCtrls, TeeProcs, Chart;
-
- { See below the MakeISOAxis routine.
- This routine will change the axis scales to be isometric
- with the screen size and video mode pixel size.
-
- So, both the Left and Bottom axis will have equivalent
- distance on screen for the same Axis Increment.
- This makes the grid lines to appear "squared".
- }
-
- type
- TIsoMetricAxisForm = class(TForm)
- Chart1: TChart;
- Series1: TFastLineSeries;
- ScrollBar1: TScrollBar;
- Label1: TLabel;
- Label2: TLabel;
- Button1: TButton;
- Button2: TButton;
- CheckBox1: TCheckBox;
- procedure Chart1UndoZoom(Sender: TObject);
- procedure ScrollBar1Change(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure Chart1Zoom(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure CheckBox1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- IsoMetricAxisForm: TIsoMetricAxisForm;
-
- implementation
-
- {$R *.DFM}
-
- { Call this function with a Chart or DBChart component
- to adjust the axis scales isometrically:
-
- MakeISOAxis( Chart1 );
- }
- Procedure MakeIsoAxis(AChart:TCustomChart);
- var tmpX,tmpY,XRange,YRange,Offset,XYScreen:Double;
- begin
- With AChart do
- if (ChartHeight>0) and (ChartWidth>0) then
- begin
- With BottomAxis do XRange:=Maximum-Minimum;
- With LeftAxis do YRange:=Maximum-Minimum;
-
- XYScreen:=1.0*(GetDeviceCaps(Canvas.Handle,HORZSIZE)/Screen.Width)/
- (GetDeviceCaps(Canvas.Handle,VERTSIZE)/Screen.Height);
-
- tmpX:=(XRange/ChartWidth);
- tmpY:=(YRange/ChartHeight)*XYScreen;
-
- if tmpX>tmpY then
- begin
- if tmpY<>0 then
- begin
- Offset:=((YRange*tmpX/tmpY)-YRange)/2.0;
- With LeftAxis do SetMinMax(Minimum-Offset,Maximum+Offset);
- end;
- end
- else
- if tmpX<>0 then
- begin
- Offset:=((XRange*tmpY/tmpX)-XRange)/2.0;
- With BottomAxis do SetMinMax(Minimum-Offset,Maximum+Offset);
- end;
- end;
- end;
-
- { If user unzooms the Chart with left mouse button, repeat isoaxis: }
- procedure TIsoMetricAxisForm.Chart1UndoZoom(Sender: TObject);
- begin
- MakeISOAxis(Chart1);
- end;
-
- { This scrollbar is used in this example to change the axes increment... }
- procedure TIsoMetricAxisForm.ScrollBar1Change(Sender: TObject);
- begin
- With Chart1 do
- begin
- LeftAxis.Increment :=ScrollBar1.Position*10;
- BottomAxis.Increment:=ScrollBar1.Position*10;
- Label2.Caption:=FloatToStr(LeftAxis.Increment);
- end;
- end;
-
- { Add sample value and initialize the example controls... }
- procedure TIsoMetricAxisForm.FormCreate(Sender: TObject);
- begin
- Series1.FillSampleValues(100);
- ScrollBar1Change(Self);
- CheckBox1Click(Self);
- end;
-
- { After Zooming the Chart, remake ISO axis: }
- procedure TIsoMetricAxisForm.Chart1Zoom(Sender: TObject);
- begin
- MakeISOAxis(Chart1);
- end;
-
- procedure TIsoMetricAxisForm.Button1Click(Sender: TObject);
- begin
- Close;
- end;
-
- procedure TIsoMetricAxisForm.Button2Click(Sender: TObject);
- begin
- MakeISOAxis(Chart1);
- end;
-
- { When Axis.LabelsSeparation is zero, the axis will
- display all labels without checking for anti-overlapping.
- }
- procedure TIsoMetricAxisForm.CheckBox1Click(Sender: TObject);
- begin
- if CheckBox1.Checked then
- begin
- Chart1.LeftAxis.LabelsSeparation:=0;
- Chart1.BottomAxis.LabelsSeparation:=0;
- end
- else
- begin
- Chart1.LeftAxis.LabelsSeparation:=10;
- Chart1.BottomAxis.LabelsSeparation:=10;
- end;
- end;
-
- end.
-