Returning the X axis label when moving mouse

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

Returning the X axis label when moving mouse

Post by Phineas » Mon Feb 23, 2009 8:51 pm

I'm having a problem returning the X axis label.
I load up the candle chart thus.

With Series1 do
begin
For X := 1 To NumRecs do
begin
AddCandle( X,
Stock_Data[X].Open,
Stock_Data[X].High,
Stock_Data[X].Low,
Stock_Data[X].CloseP);

DecodeDate(Stock_Data[X].Date, tmpYear, tmpMonth, tmpDay );
Labels[X]:= FormatFloat('0000',tmpYear)+
FormatFloat('00',tmpMonth)+
FormatFloat('00',tmpDay);
end;
end;

It is a scrolling chart with over 3000 records.
While moving the mouse over the Series, I need to return the label for the mouse X position.



Thanks in advance.

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

Post by Yeray » Tue Feb 24, 2009 10:42 am

Hi Phineas,

Could you take a look at this post? I think it's pretty similar than what you are looking for.
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

Phineas
Newbie
Newbie
Posts: 18
Joined: Wed Apr 09, 2008 12:00 am

Post by Phineas » Tue Feb 24, 2009 8:13 pm

Yeray, the code you suggest will only function while the mouse is over the actual series. I require the X value as a date returned while the mouse is moving anywhere over the entire chart.

I managed it thus.

ValueIndex := Round(Series1.XScreenToValue(X));

Edit1.Text := Series1.Labels[ValueIndex];

I am not happy with having the ROUND statement. This can have the effect of not being accurate some of the time. Is there a better way?

Thanx.

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

Post by Yeray » Wed Feb 25, 2009 9:08 am

Hi Phineas,

Excuse me. I think I didn't understand well your request. To retrieve the corresponding value in bottom axis for an x point, you could do as follows:

Code: Select all

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
    caption := floattostr(Chart1.Axes.Bottom.CalcPosPoint(X));
end;
Then if you want to get the corresponding series' value index, you should use a round or a trunc function.
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