Page 1 of 1

Returning the X axis label when moving mouse

Posted: Mon Feb 23, 2009 8:51 pm
by 10548832
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.

Posted: Tue Feb 24, 2009 10:42 am
by yeray
Hi Phineas,

Could you take a look at this post? I think it's pretty similar than what you are looking for.

Posted: Tue Feb 24, 2009 8:13 pm
by 10548832
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.

Posted: Wed Feb 25, 2009 9:08 am
by yeray
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.