Web forum is in read-only mode. Login as active registered customer for write access
  Forum Search   New Posts New Posts

Using Mouse to Move Chart Point

 Post Reply Post Reply
Author
Pocock Jon View Drop Down
New Member
New Member
Avatar

Joined: 11 Nov 2010
Posts: 2
Post Options Post Options   Quote Pocock Jon Quote  Post ReplyReply Direct Link To This Post Topic: Using Mouse to Move Chart Point
    Posted: 09 Feb 2011 at 3:57pm
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

Back to Top
Pieter Scheldeman View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 3463
Post Options Post Options   Quote Pieter Scheldeman Quote  Post ReplyReply Direct Link To This Post Posted: 10 Feb 2011 at 7:08am
Dear Mr. Pocock, 

We have uploaded a sample which demonstrates this functionality:
http://www.tmssoftware.net/public/Demo_4.zip

Kind Regards,
Pieter

Back to Top
Pocock Jon View Drop Down
New Member
New Member
Avatar

Joined: 11 Nov 2010
Posts: 2
Post Options Post Options   Quote Pocock Jon Quote  Post ReplyReply Direct Link To This Post Posted: 10 Feb 2011 at 9:24am
Pieter

Thanks for your prompt response.
After I posted I had found the YtoValue and XtoValue functions, so had made some progress.  However the new XYtoSeriesPoint function in v3 makes the whole process much easier :-)  I shall make much use of this

Best wishes

Jon

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down