home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / DELPHI4.EXE / %MAINDIR% / Examples / Extended / Uclick.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-11-17  |  2.8 KB  |  95 lines

  1. unit Uclick;
  2. { This example shows how to obtain information when the user
  3.   clicks on a Series point.
  4. }
  5. interface
  6.  
  7. uses
  8.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  9.   Forms, Dialogs, TeEngine, Series, ExtCtrls, TeeProcs, Chart, StdCtrls;
  10.  
  11. type
  12.   TClickingForm = class(TForm)
  13.     Chart1: TChart;
  14.     Series1: TPointSeries;
  15.     Label1: TLabel;
  16.     Button1: TButton;
  17.     procedure FormCreate(Sender: TObject);
  18.     procedure Chart1ClickSeries(Sender: TCustomChart; Series: TChartSeries;
  19.       ValueIndex: Longint; Button: TMouseButton; Shift: TShiftState; X,
  20.       Y: Integer);
  21.     procedure Button1Click(Sender: TObject);
  22.     procedure Chart1ClickLegend(Sender: TCustomChart; Button: TMouseButton;
  23.       Shift: TShiftState; X, Y: Integer);
  24.     procedure Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  25.       Y: Integer);
  26.   private
  27.     { Private declarations }
  28.   public
  29.     { Public declarations }
  30.   end;
  31.  
  32. var
  33.   ClickingForm: TClickingForm;
  34.  
  35. implementation
  36.  
  37. {$R *.DFM}
  38.  
  39. procedure TClickingForm.FormCreate(Sender: TObject);
  40. begin
  41.   { sample values... }
  42.   With Series1 do
  43.   begin
  44.     Add( 100, 'John',  clRed );
  45.     Add(  70, 'Mary',  clYellow );
  46.     Add( 130, 'Mike',  clBlue );
  47.     Add( 190, 'Peter', clGreen );
  48.   end;
  49.  
  50.   { nice cursor }
  51.   Series1.Cursor:=crTeeHand;
  52. end;
  53.  
  54. { Use this event to get notified when users click over a
  55.   Series point (or Bar, or Line, etc)
  56. }
  57. procedure TClickingForm.Chart1ClickSeries(Sender: TCustomChart;
  58.   Series: TChartSeries; ValueIndex: Longint; Button: TMouseButton;
  59.   Shift: TShiftState; X, Y: Integer);
  60. begin
  61.   ShowMessage( 'Point has been clicked ! ' +#13+#13+
  62.                'Series: '+Series.Name +#13+
  63.                'Point Index: '+IntToStr( ValueIndex )+ #13+
  64.                'Point Value: '+FloatToStr(Series.YValue[ValueIndex])+ #13+
  65.                'Point Label: '+Series.XLabel[ValueIndex]+ #13+
  66.                'Point Color: '+ColorToString(Series.ValueColor[ValueIndex])+#13+#13+
  67.                'Advanced: '+#13+
  68.                'Point X pixel coordinate: '+IntToStr(Series.CalcXPos(ValueIndex))+#13+
  69.                'Point Y pixel coordinate: '+IntToStr(Series.CalcYPos(ValueIndex))
  70.               );
  71. end;
  72.  
  73. procedure TClickingForm.Button1Click(Sender: TObject);
  74. begin
  75.   Close;
  76. end;
  77.  
  78. procedure TClickingForm.Chart1ClickLegend(Sender: TCustomChart;
  79.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  80. var tmp:Integer;
  81. begin
  82.   tmp:=Chart1.Legend.Clicked(x,y);
  83.   if tmp<>-1 then Chart1ClickSeries(Sender,Series1,tmp,Button,Shift,X,Y);
  84. end;
  85.  
  86. procedure TClickingForm.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  87.   Y: Integer);
  88. begin
  89.   if Chart1.Legend.Clicked(x,y)<>-1 then Chart1.Cursor:=crTeeHand
  90.                                     else Chart1.Cursor:=crDefault;
  91.   Chart1.OriginalCursor:=Chart1.Cursor;
  92. end;
  93.  
  94. end.
  95.