home *** CD-ROM | disk | FTP | other *** search
- {*********************************************}
- { TeeChart Pro 4 example }
- { Copyright (c) 1995-1998 by David Berneda }
- { All rights reserved }
- {*********************************************}
- unit Utips;
- {$P-} { <-- for Delphi 1 compatibility }
-
- interface
-
- { This example shows how to customize Series Marks.
- A single Mark is displayed, when the user clicks on a Bar.
- The OnGetMarkText event is used to select which Mark should
- be displayed.
-
- The example also draws a rectangle around the Bar and the Legend
- item.
- }
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, TeEngine, Series, ExtCtrls, TeeProcs, Chart, StdCtrls;
-
- type
- TFormMarkTips = class(TForm)
- Chart1: TChart;
- Series1: TBarSeries;
- Button1: TButton;
- CheckBox1: TCheckBox;
- Memo1: TMemo;
- procedure FormCreate(Sender: TObject);
- procedure Series1GetMarkText(Sender: TChartSeries; ValueIndex: Integer;
- var MarkText: String);
- procedure Series1Click(Sender: TChartSeries; ValueIndex: Integer;
- Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- procedure Chart1AfterDraw(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- private
- { Private declarations }
- public
- { Public declarations }
- ClickedBar:Integer;
- end;
-
- var
- FormMarkTips: TFormMarkTips;
-
- implementation
-
- {$R *.DFM}
-
- procedure TFormMarkTips.FormCreate(Sender: TObject);
- begin
- ClickedBar:=-1; { <-- temporary variable to store the "clicked" index }
- With Series1 do
- begin
- FillSampleValues(8); { <-- random data }
- Cursor:=crTeeHand; { <-- nice cursor }
- AutoMarkPosition:=False; { <-- do not move marks positions }
- end;
- end;
-
- { This event is called for each Mark in the Series }
- procedure TFormMarkTips.Series1GetMarkText(Sender: TChartSeries;
- ValueIndex: Integer; var MarkText: String);
- begin
- if ValueIndex<>ClickedBar then { <-- is this the "clicked" bar? }
- MarkText:='' { <-- if not, do not draw mark }
- else
- { if yes, set mark color to be the same as bar color }
- Series1.Marks.BackColor:=Series1.ValueColor[ClickedBar];
- end;
-
- { This event is called when user clicks on a Bar point... }
- procedure TFormMarkTips.Series1Click(Sender: TChartSeries; ValueIndex: Integer;
- Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- begin
- ClickedBar:=ValueIndex; { <-- User has clicked a bar !! Store which }
- Chart1.Repaint; { <-- force repaint to show new clicked bar... }
- end;
-
- { This event is called each time the Chart redraws... }
- procedure TFormMarkTips.Chart1AfterDraw(Sender: TObject);
- var tmp,x0,y0,x1,y1:Integer;
- begin
- if ClickedBar<>-1 then { <-- if user clicked on a bar... }
- With Series1,Chart1.Canvas do
- begin
- Pen.Style:=psDot; { <-- set pen attributes }
- Pen.Width:=1;
-
- { check pen color is not the same as clicked bar color,
- otherwise the rectangle will not be visible ! }
- if ValueColor[ClickedBar]=clWhite then
- Pen.Color:=clRed
- else
- Pen.Color:=clWhite;
-
- { set brush to clear to not fill the rectangle... }
- Brush.Style:=bsClear;
-
- { calculate the rectangle coordinates of the rectangle... }
- tmp:=CalcXPos(ClickedBar);
- x0:=tmp;
- x1:=tmp+BarWidth;
- y0:=CalcYPosValue(PointOrigin(ClickedBar,True)); { <-- bar bottom }
- y1:=CalcYPos(ClickedBar);
-
- { draw the rectangle }
- {$IFDEF GL}
- RectangleWithZ(Rect(x0,y0,x1,y1),0);
- {$ELSE}
- Rectangle(x0,y0,x1,y1);
- {$ENDIF}
-
- { draw another rectangle at legend item... }
- With (Chart1.Legend as TChartLegend).RectLegend do
- begin
- x0:=Left;
- x1:=Right;
- Chart1.FontCanvas(Chart1.Legend.Font);
- tmp:=Chart1.Canvas.TextHeight('W');
- y0:=Top+ClickedBar*tmp+1;
- y1:=y0+tmp;
- end;
- Pen.Color:=clBlue;
- Rectangle(x0,y0,x1,y1);
- end;
- end;
-
- procedure TFormMarkTips.Button1Click(Sender: TObject);
- begin
- Close;
- end;
-
- procedure TFormMarkTips.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- var NewClickedBar:Integer;
- begin
- if CheckBox1.Checked then { <-- if "Follow mouse" is checked ... }
- begin
- NewClickedBar:=Series1.Clicked(X,Y);
- if (NewClickedBar<>-1) and (NewClickedBar<>ClickedBar) then
- begin
- ClickedBar:=NewClickedBar; { <-- set ClickedBar automatically... }
- Chart1.Repaint;
- end;
- end;
- end;
-
- end. { end for today... <g> }
-
-