Cursor x and y values

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
sunman4008
Newbie
Newbie
Posts: 18
Joined: Tue Apr 09, 2013 12:00 am

Cursor x and y values

Post by sunman4008 » Tue Apr 09, 2013 2:09 pm

Hello,

How do I show a crosshair cursor which displays the X-axis and the Y-axis values?

-Mike

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Cursor x and y values

Post by Yeray » Wed Apr 10, 2013 10:27 am

Hi Mike,

Looks like this, isn't it?
http://www.teechart.net/support/viewtop ... f=3&t=6964
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

sunman4008
Newbie
Newbie
Posts: 18
Joined: Tue Apr 09, 2013 12:00 am

Re: Cursor x and y values

Post by sunman4008 » Thu Apr 18, 2013 12:06 am

Hello,

What is ChartTool2 in the example? What does it mean by Annotion Tool?

Also...the picture are not shown.

-Mike

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Cursor x and y values

Post by Yeray » Thu Apr 18, 2013 9:15 am

Hi Mike,

Sorry if it wasn't clear enough.
I've made a more complete example from it. You only need to add a Chart to the form at design time and the following code:

Code: Select all

uses {...} Series, TeeTools;
//...
  private
    { Private declarations }
    procedure cursorToolChange(Sender: TCursorTool; x, y: Integer;
      const XValue, YValue: Double; Series: TChartSeries; ValueIndex: Integer);
//...
var cursorTool: TCursorTool;
    annotatTool: TAnnotationTool;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=false;
  Chart1.AddSeries(TPointSeries).FillSampleValues;

  cursorTool:=Chart1.Tools.Add(TCursorTool) as TCursorTool;
  cursorTool.OnChange:=cursorToolChange;

  annotatTool:=Chart1.Tools.Add(TAnnotationTool) as TAnnotationTool;
  annotatTool.PositionUnits := muPixels;
  annotatTool.Shape.CustomPosition := true;

  Chart1.Draw;

  annotatTool.Shape.Top := Chart1.Axes.Bottom.PosAxis + 20;
end;

procedure TForm1.cursorToolChange(Sender: TCursorTool; x, y: Integer;
  const XValue, YValue: Double; Series: TChartSeries; ValueIndex: Integer);
begin
  annotatTool.Text := floattostr(XValue);
  Chart1.Draw;
  annotatTool.Shape.Left := Chart1.Axes.Bottom.CalcXPosValue(XValue) - (annotatTool.Shape.Width div 2);
  Caption := 'X: ' + floattostr(XValue) + '    Y: ' + floattostr(YValue);
end;
Don't hesitate to let us know if you find any problem when adapting it to your specific needs.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply