Yes I noticed that too. WP's code example was really helpful but I realized I didnt ask the question clearly.
I moved it to the Chart object OnMouseMove event and did it this way:
procedure TChartForm.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
var
ext: TDoubleRect;
P : TDoublePoint;
G : TPoint;
begin
If Not Chart1.Enabled then
Exit;
Chart1.Repaint;
G.X := X;
G.Y := Y;
P := Chart1.ImageToGraph(G);
ext := Chart1.CurrentExtent;
if InRange(P.X, ext.a.X, ext.b.x) and InRange(P.Y, ext.a.Y, ext.b.Y) then
begin
Chart1ConstantLine1.Position := P.Y;
Chart1ConstantLine2.Position := P.X;
Chart1ConstantLine1.Active := true;
Chart1ConstantLine2.Active := true;
end
Else
begin
Chart1ConstantLine1.Active := false;
Chart1ConstantLine2.Active := false;
end;
end;
Of course you'll have to define 2 ConstantLine series and set Chart1ConstantLine1.LineStyle to lsHorizontal and #2 to lsVertical. Also set the SeriesColor to something other than the chart background
keep the chart inactive until populate your lineseries with the stock price and time. This will draw the crosshairs all the way across the chart area. And only when you move the cursor off of that drawing area will the crosshairs go away.