Page 1 of 1

Add value on mouse pos

Posted: Fri Sep 16, 2005 8:06 am
by 8439897
When I click on the chart I want to add a value on this position. How can I calculate the chart x/y position from the mouse position?

Posted: Fri Sep 16, 2005 10:21 am
by narcis
Hi CT,

You can do that using TChart's OnMouseDown event:

Code: Select all

procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var xval, yval: Double;
begin
  xval:=Series1.XScreenToValue(X);
  yval:=Series1.YScreenToValue(Y);

  Series1.AddXY(xval,yval);
end;

Posted: Fri Sep 16, 2005 11:24 am
by 8439897
Hm, xval and yval are always 0. I try it out with a fresh chart, having one series.

Posted: Fri Sep 16, 2005 11:53 am
by narcis
Hi CT,

This is because to get it working you need to already have some values on the series as done here:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Series1.FillSampleValues(2);
end;

procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var xval, yval: Double;
begin
  xval:=Series1.XScreenToValue(X);
  yval:=Series1.YScreenToValue(Y);

  Series1.AddXY(xval,yval);
end;
Other alternatives would be using a TDrawLineTool or custom drawing on TChart's canvas.

For more information on TChart tools please have a look at the features demo at the TeeChart program group. For information on how to custom draw on the canvas, have a look at the tutorials at the TeeChart "Docs" folder and on the features demo as well.

Posted: Fri Sep 16, 2005 2:46 pm
by 8439897
Even I have some values added it does not work. All values are added on 0, 0 but if I scroll the chart a little bit it workes. For my needs that is OK.

Posted: Mon Sep 19, 2005 7:29 am
by narcis
Hi CT,

It's ok for us if it's ok for your needs. However if you want us to look further at it please send us an example we can run "as-is" to reproduce the problem here spceifying wich TeeChart version you are using.

You can post your files at [url]news://www.steema.net/steema.public.attachments[/url] newsgroup.