unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, TeEngine, Series, ExtCtrls, TeeProcs, Chart;
type
TForm1 = class(TForm)
Chart1: TChart;
Series1: TLineSeries;
procedure FormCreate(Sender: TObject);
procedure Chart1MouseMove(Sender: TObject;
Shift: TShiftState;
X,
Y: Integer);
procedure Chart1MouseWheel(Sender: TObject;
Shift: TShiftState;
WheelDelta: Integer;
MousePos: TPoint;
var Handled: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
Randomize;
for i := 0 to 20do
Series1.AddXY(i, Random(100));
end;
procedure TForm1.Chart1MouseMove(Sender: TObject;
Shift: TShiftState;
X,
Y: Integer);
begin
Chart1.SetFocus;
end;
procedure TForm1.Chart1MouseWheel(Sender: TObject;
Shift: TShiftState;
WheelDelta: Integer;
MousePos: TPoint;
var Handled: Boolean);
var
x1, x2, s:do
uble;
begin
//
x1 := Chart1.BottomAxis.Minimum;
x2 := Chart1.BottomAxis.Maximum;
if WheelDelta < 0 then
begin
s := (x2 - x1) / 4;
if s < 0.001 then
s := 0.001;
x1 := x1 - s;
x2 := x2 + s;
end
else
begin
s := (x2 - x1) / 5;
if s < 0.001 then
s := 0.001;
x1 := x1 + s;
x2 := x2 - s;
end;
Chart1.BottomAxis.SetMinMax(x1, x2);
Handled := true;
//主要是这句
end;
end.