I'd like my users to be able to use a chart to input data.
I have a TAdvChartView which displays the data.
I have set up onmouse events
I use MouseDown to identify the specific point that the user selects
I use OnMouseMove to change the position of the point.
However the only information supplied in this call is the Mouse X and Y coords.
So to do the movement correctly I need to know the current scaling on the axis so I can convert the X/Y movement into actual chart values....
Any suggestions/ideas how I can do this ?
Or perhaps there is a better way of doing this?
Here's extracts from my current code ...
TJTRChartFrame = class(TFrame)
Chart: TAdvChartView;
AdjustChart : boolean;
AdjustPoint : TChartPoint;
AdjustActive : boolean;
AdjustStartX : integer;
AdjustStartY : integer;
AdjustStartV : double;
AdjustStartT : integer;
end;
procedure TJTRChartFrame.ChartMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
t : integer;
begin
if (Button = mbLeft) and
Chart.Panes[0].Crosshair.Visible and
AdjustChart then
begin
AdjustPoint := Chart.Panes[0].GetChartPointAtCrossHair(0);
AdjustActive := true;
AdjustStartX := X;
AdjustStartY := Y;
AdjustStartV := AdjustPoint.SingleValue;
AdjustStartT := Trunc(AdjustPoint.TimeStamp * (MaxTimePeriods+1));
end;
end;
procedure TJTRChartFrame.ChartMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
t : integer;
begin
if AdjustActive then
begin
Chart.BeginUpdate;
t := Trunc(AdjustPoint.TimeStamp * (MaxTimePeriods+1));
Chart.Panes[0].Series[0].
SetSinglePoint(AdjustStartV*(1+(X-AdjustStartX)/1{XScale}),
AdjustStartT);
Chart.EndUpdate;
end;
end;
Thanks
Jon