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

  1. {****************************************}
  2. {    TeeChart. TChart Component          }
  3. { Copyright (c) 1995-98 by David Berneda }
  4. {    All Rights Reserved                 }
  5. {****************************************}
  6. unit UMultAxi;
  7.  
  8. interface
  9.  
  10. uses
  11.   WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  12.   TeEngine, Series, ExtCtrls, TeeProcs, Chart, CandleCh, OHLChart,
  13.   StdCtrls, TeeComma;
  14.  
  15. type
  16.   TFormMultipleAxes = class(TForm)
  17.     Chart1: TChart;
  18.     Series1: TLineSeries;
  19.     Series2: TLineSeries;
  20.     Series3: TCandleSeries;
  21.     Series4: TVolumeSeries;
  22.     Panel1: TPanel;
  23.     CheckBox1: TCheckBox;
  24.     CheckBox2: TCheckBox;
  25.     ScrollBar1: TScrollBar;
  26.     Label1: TLabel;
  27.     CheckBox3: TCheckBox;
  28.     Timer1: TTimer;
  29.     CheckBox4: TCheckBox;
  30.     CheckBox5: TCheckBox;
  31.     CheckBox6: TCheckBox;
  32.     CheckBox7: TCheckBox;
  33.     CheckBox8: TCheckBox;
  34.     CheckBox9: TCheckBox;
  35.     TeeCommander1: TTeeCommander;
  36.     Button1: TButton;
  37.     procedure FormCreate(Sender: TObject);
  38.     procedure Chart1AfterDraw(Sender: TObject);
  39.     procedure Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  40.       Y: Integer);
  41.     procedure Chart1MouseDown(Sender: TObject; Button: TMouseButton;
  42.       Shift: TShiftState; X, Y: Integer);
  43.     procedure Chart1MouseUp(Sender: TObject; Button: TMouseButton;
  44.       Shift: TShiftState; X, Y: Integer);
  45.     procedure Chart1AllowScroll(Sender: TChartAxis; var AMin, AMax: Double;
  46.       var AllowScroll: Boolean);
  47.     procedure CheckBox1Click(Sender: TObject);
  48.     procedure CheckBox2Click(Sender: TObject);
  49.     procedure ScrollBar1Change(Sender: TObject);
  50.     procedure CheckBox3Click(Sender: TObject);
  51.     procedure Timer1Timer(Sender: TObject);
  52.     procedure CheckBox4Click(Sender: TObject);
  53.     procedure CheckBox6Click(Sender: TObject);
  54.     procedure CheckBox5Click(Sender: TObject);
  55.     procedure CheckBox7Click(Sender: TObject);
  56.     procedure CheckBox8Click(Sender: TObject);
  57.     procedure CheckBox9Click(Sender: TObject);
  58.     procedure Button1Click(Sender: TObject);
  59.   private
  60.     { Private declarations }
  61.   public
  62.     { Public declarations }
  63.     Axis1,Axis2:TChartAxis;
  64.     DeltaRotation,
  65.     DeltaAxis1,DeltaAxis2,
  66.     DeltaZoom,
  67.     DeltaRight,DeltaLeft:Integer;
  68.     DraggingLine:Boolean;
  69.     Procedure CheckRightAxis;
  70.   end;
  71.  
  72. var
  73.   FormMultipleAxes: TFormMultipleAxes;
  74.  
  75. implementation
  76.  
  77. {$R *.DFM}
  78. Uses TeCanvas;  { <-- only needed for "ZoomText" special Canvas property }
  79.  
  80. procedure TFormMultipleAxes.FormCreate(Sender: TObject);
  81. begin
  82.   DeltaRotation:=2;
  83.   DeltaAxis1:=1;
  84.   DeltaAxis2:=1;
  85.   DeltaRight:=2;
  86.   DeltaLeft:=2;
  87.   DeltaZoom:=2;
  88.  
  89.   DraggingLine:=False;
  90.   ScrollBar1.Position:=Chart1.View3DOptions.Rotation;
  91.  
  92.   Chart1.MarginLeft:=10;
  93.   Chart1.ClipPoints:=False;
  94.   Chart1.Gradient.Visible:=Chart1.IsScreenHighColor;
  95.   CheckBox5.Checked:=Chart1.Gradient.Visible;
  96.  
  97.   Axis1:=TChartAxis.Create(Chart1);
  98.   With Axis1 do
  99.   begin
  100.     Horizontal:=False;
  101.     StartPosition:=50;
  102.     EndPosition:=100;
  103.     LabelsFont.Color:=Series2.SeriesColor;
  104.   end;
  105.   Series2.CustomVertAxis:=Axis1;
  106.  
  107.   Axis2:=TChartAxis.Create(Chart1);
  108.   With Axis2 do
  109.   begin
  110.     Horizontal:=False;
  111.     StartPosition:=0;
  112.     EndPosition:=50;
  113.     LabelsFont.Color:=Series3.SeriesColor;
  114.     PositionPercent:=-10;
  115.     Grid.Visible:=False;
  116.   end;
  117.   Series3.CustomVertAxis:=Axis2;
  118.  
  119.   Chart1.LeftAxis.EndPosition:=50;
  120.   Chart1.LeftAxis.LabelsFont.Color:=Series1.SeriesColor;
  121.  
  122.   Series1.FillSampleValues(20);
  123.   Series3.FillSampleValues(20);
  124.   Series4.FillSampleValues(120);
  125.   Series2.FillSampleValues(20);
  126.  
  127.   Series4.VertAxis:=aRightAxis;
  128.  
  129.   With Chart1.RightAxis do
  130.   begin
  131.     StartPosition:=50;
  132.     Maximum:=Series4.YValues.MaxValue*2;
  133.     AutomaticMaximum:=False;
  134.     Grid.Visible:=False;
  135.     LabelsFont.Color:=Series4.SeriesColor;
  136.   end;
  137.  
  138.   Series2.HorizAxis:=aTopAxis;
  139.   Chart1.TopAxis.Grid.Visible:=False;
  140.   Series2.ZOrder:=0;
  141. end;
  142.  
  143. procedure TFormMultipleAxes.Chart1AfterDraw(Sender: TObject);
  144. begin
  145.   { draw an horizontal line at left axis bottom position }
  146.   With Chart1,Canvas do
  147.   begin
  148.     Pen.Color:=clGray;
  149.     Pen.Width:=2;
  150.     Pen.Style:=psSolid;
  151.     MoveTo3D(ChartRect.Left,LeftAxis.IEndPos,0);
  152.     LineTo3D(ChartRect.Right,LeftAxis.IEndPos,0);
  153.   end;
  154. end;
  155.  
  156. Procedure TFormMultipleAxes.CheckRightAxis;
  157. begin
  158.   if CheckBox1.Checked then Chart1.RightAxis.StartPosition:=Axis1.StartPosition;
  159. end;
  160.  
  161. procedure TFormMultipleAxes.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  162.   Y: Integer);
  163. begin
  164.   if DraggingLine then
  165.   begin
  166.     Chart1.LeftAxis.EndPosition:=Round((Y-Chart1.ChartRect.Top)*100.0/Chart1.ChartHeight);
  167.     Axis1.StartPosition:=Chart1.LeftAxis.EndPosition;
  168.     Axis2.EndPosition:=Chart1.LeftAxis.EndPosition;
  169.     CheckRightAxis;
  170.   end
  171.   else
  172.   begin
  173.     if Abs(Y-Chart1.LeftAxis.IEndPos)<4 then Chart1.Cursor:=crTeeHand
  174.                                         else Chart1.Cursor:=crDefault;
  175.     Chart1.OriginalCursor:=Chart1.Cursor;
  176.   end;
  177. end;
  178.  
  179. procedure TFormMultipleAxes.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
  180.   Shift: TShiftState; X, Y: Integer);
  181. begin
  182.   DraggingLine:=(not Timer1.Enabled) and (Chart1.Cursor=crTeeHand);
  183.   Chart1.CancelMouse:=DraggingLine;
  184. end;
  185.  
  186. procedure TFormMultipleAxes.Chart1MouseUp(Sender: TObject; Button: TMouseButton;
  187.   Shift: TShiftState; X, Y: Integer);
  188. begin
  189.   DraggingLine:=False;
  190.   Chart1.CancelMouse:=False;
  191. end;
  192.  
  193. procedure TFormMultipleAxes.Chart1AllowScroll(Sender: TChartAxis; var AMin,
  194.   AMax: Double; var AllowScroll: Boolean);
  195. begin
  196.   AllowScroll:=Sender<>Chart1.RightAxis;
  197. end;
  198.  
  199. procedure TFormMultipleAxes.CheckBox1Click(Sender: TObject);
  200. begin
  201.  CheckRightAxis;
  202. end;
  203.  
  204. procedure TFormMultipleAxes.CheckBox2Click(Sender: TObject);
  205. begin
  206.   Chart1.View3D:=CheckBox2.Checked;
  207.   Chart1.View3DOptions.Orthogonal:=False;
  208.   ScrollBar1.Enabled:=Chart1.View3D;
  209.   if not Chart1.View3D then CheckBox9.Checked:=False;
  210. end;
  211.  
  212. procedure TFormMultipleAxes.ScrollBar1Change(Sender: TObject);
  213. begin
  214.   Chart1.View3DOptions.Rotation:=ScrollBar1.Position;
  215. end;
  216.  
  217. procedure TFormMultipleAxes.CheckBox3Click(Sender: TObject);
  218. begin
  219.   Timer1.Enabled:=CheckBox3.Checked;
  220.   CheckBox1.Enabled:=not Timer1.Enabled;
  221.   Chart1.Foot.Visible:=not Timer1.Enabled;
  222.   CheckBox4.Enabled:=Timer1.Enabled;
  223.   CheckBox9.Enabled:=Timer1.Enabled;
  224. end;
  225.  
  226. procedure TFormMultipleAxes.Timer1Timer(Sender: TObject);
  227.  
  228.   Procedure CheckDelta(Var D:Integer; Const Value:Double; Min,Max:Integer);
  229.   begin
  230.     if (D<0) and (Value<Min+5) then D:=-D else
  231.     if (D>0) and (Value>Max-5) then D:=-D;
  232.   end;
  233.  
  234. var MinAngle:Integer;
  235. begin
  236.   if CheckBox9.Checked then
  237.   begin
  238.     Chart1.View3D:=True;
  239.     With Chart1.View3DOptions do
  240.     begin
  241.       Orthogonal:=False;
  242.       Rotation:=Rotation+DeltaRotation;
  243.       if Chart1.Canvas.SupportsFullRotation then MinAngle:=0
  244.                                             else MinAngle:=270;
  245.       CheckDelta(DeltaRotation,Rotation,MinAngle,360);
  246.       Zoom:=Zoom+DeltaZoom;
  247.       CheckDelta(DeltaZoom,Zoom,20,120);
  248.     end;
  249.   end;
  250.   Axis1.StartPosition:=Axis1.StartPosition+DeltaAxis1;
  251.   CheckDelta(DeltaAxis1,Axis1.StartPosition,0,75);
  252.  
  253.   Axis2.StartPosition:=Axis2.StartPosition+DeltaAxis2;
  254.   Axis2.EndPosition:=Axis2.EndPosition+DeltaAxis2;
  255.   CheckDelta(DeltaAxis2,Axis2.EndPosition,0,95);
  256.  
  257.   With Chart1.RightAxis do
  258.   begin
  259.     PositionPercent:=PositionPercent+DeltaRight;
  260.     CheckDelta(DeltaRight,PositionPercent,-10,110);
  261.   end;
  262.   With Chart1.LeftAxis do
  263.   begin
  264.     PositionPercent:=PositionPercent+DeltaLeft;
  265.     CheckDelta(DeltaLeft,PositionPercent,-10,110);
  266.   end;
  267. end;
  268.  
  269. procedure TFormMultipleAxes.CheckBox4Click(Sender: TObject);
  270. begin
  271.   Chart1.View3DOptions.ZoomText:=CheckBox4.Checked;
  272. end;
  273.  
  274. procedure TFormMultipleAxes.CheckBox6Click(Sender: TObject);
  275. begin
  276.   Chart1.AxisVisible:=CheckBox6.Checked;
  277. end;
  278.  
  279. procedure TFormMultipleAxes.CheckBox5Click(Sender: TObject);
  280. begin
  281.   Chart1.Gradient.Visible:=CheckBox5.Checked;
  282. end;
  283.  
  284. procedure TFormMultipleAxes.CheckBox7Click(Sender: TObject);
  285. begin
  286.   Chart1.Legend.Visible:=CheckBox7.Checked;
  287. end;
  288.  
  289. procedure TFormMultipleAxes.CheckBox8Click(Sender: TObject);
  290. begin
  291.   Chart1.View3DWalls:=CheckBox8.Checked;
  292.   With Chart1.BackWall.Brush do
  293.   if Chart1.View3DWalls then Style:=bsSolid
  294.                         else Style:=bsClear;
  295.   Chart1.BackWall.Pen.Visible:=Chart1.View3DWalls;
  296. end;
  297.  
  298. procedure TFormMultipleAxes.CheckBox9Click(Sender: TObject);
  299. begin
  300.   CheckBox2.Checked:=True;
  301. end;
  302.  
  303. procedure TFormMultipleAxes.Button1Click(Sender: TObject);
  304. begin
  305.   Close;
  306. end;
  307.  
  308. end.
  309.