Add value on mouse pos

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
CT
Newbie
Newbie
Posts: 12
Joined: Fri Nov 15, 2002 12:00 am
Location: Germany
Contact:

Add value on mouse pos

Post by CT » Fri Sep 16, 2005 8:06 am

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?

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Sep 16, 2005 10:21 am

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;
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

CT
Newbie
Newbie
Posts: 12
Joined: Fri Nov 15, 2002 12:00 am
Location: Germany
Contact:

Post by CT » Fri Sep 16, 2005 11:24 am

Hm, xval and yval are always 0. I try it out with a fresh chart, having one series.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Sep 16, 2005 11:53 am

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

CT
Newbie
Newbie
Posts: 12
Joined: Fri Nov 15, 2002 12:00 am
Location: Germany
Contact:

Post by CT » Fri Sep 16, 2005 2:46 pm

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.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon Sep 19, 2005 7:29 am

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply