Adding and Dragging Annotations at runtime
The example unit below shows how to add annotations at runtime, and allow them to be moveable dragging.
Download this unit: DragAnnotation.zip (3b)
unit DraggingAnnotation;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,Dialogs, TeEngine, Series, StdCtrls, Buttons, ExtCtrls, TeeProcs, Chart;
type
TDragAnnotation = class(TForm)
Chart1: TChart;
Panel1: TPanel;
BitBtn1: TBitBtn;
Series1: TAreaSeries;
Series2: TAreaSeries;
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure Chart1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
procedure Chart1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
FDragging: boolean;
Fitem : integer;
public
{ Public declarations }
end;
var
DragAnnotation: TDragAnnotation;
implementation
uses TeeEditPRO,teetools ;
{$R *.dfm}
procedure TDragAnnotation.FormCreate(Sender: TObject);
begin
// Adding Data to the Chart
Series1.FillSampleValues(75);
Series2.FillSampleValues(75);
// Make disable the Zoom
Chart1.Zoom.Allow:= False;
// Set the Transparency
Series2.Transparency := 45;
end;
procedure TDragAnnotation.BitBtn1Click(Sender: TObject);
var tmpStr: String;
begin
tmpStr := InputBox('ANNOTATION','Enter your Annotation','ANNOTATION');
with (Chart1.Tools.Add(TAnnotationTool.Create(Chart1)) as TAnnotationTool) do
begin
ParentChart := Chart1;
Text := tmpStr;
Shape.CustomPosition := True;
Shape.Left := 100; // add your value here
Shape.Top := 100; // add your value here
end;
end;
procedure TDragAnnotation.Chart1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var i : integer;
begin
with Chart1.Tools do
begin
for i := 0 to Count -1 do
begin
with Items[i] as TAnnotationTool do
begin
if Clicked(X,Y) then
begin
FDragging := True;
Fitem := i;
end;
end;
end
end;
end;
procedure TDragAnnotation.Chart1MouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
if FDragging then
begin
with chart1.Tools.Items[Fitem] as TAnnotationTool do
begin
Shape.CustomPosition := True;
Shape.Left := X;
Shape.Top := Y;
end;
end;
end;
procedure TDragAnnotation.Chart1MouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
FDragging := False;
end;
end.
Home | Products | Order | About us | Downloads | Support |
Copyright
information. E-MAIL info@steema.com.
Privacy
Policy All other brands and product names are trademarks or registered trademarks of their respective owners. |