Crosshair following Pointer lazarus / 55-TAChart ---------------------------------------------------------------------- chucky · 2025-02-05 20:13 I want to display a simple crosshair on my chart that's always visible even when its not close to a datapoint and also remain fixed to the pointer and not jump from point to point. Is it possble to use the TDataPointCrosshairTool for that or is their another way to create it in TChart? ---------------------------------------------------------------------- wp · 2025-02-06 10:21 Use a TUserDefinedTool and add this handler to the OnAfterMouseMove event: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  Math, TAChartUtils; procedure TForm1.ChartToolset1UserDefinedTool1AfterMouseMove(ATool: TChartTool;  APoint: TPoint);const  SIZE = 24;var  ext: TDoubleRect;  P: TDoublePoint;begin  Chart1.Repaint;  P := Chart1.ImageToGraph(APoint);  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    Chart1.Canvas.Pen.Color := clRed;    Chart1.Canvas.Pen.Style := psSolid;    Chart1.Canvas.Pen.Width := 3;  Chart1.Canvas.Line(APoint.X, APoint.Y-SIZE, APoint.X, APoint.Y+SIZE);    Chart1.Canvas.Line(APoint.X-SIZE, APoint.Y, APoint.X+SIZE, APoint.Y);  end;end; ---------------------------------------------------------------------- chucky · 2025-02-11 16:11 Thanks so Much!!! ---------------------------------------------------------------------- fpcoder · 2025-02-11 20:13 The crosshair is seen when the mouse is moved, and disappears when mouse stops to move. Should it be like that? Is it possible for the crosshair to be visible all the time? ---------------------------------------------------------------------- chucky · 2025-02-11 22:41 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: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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. ---------------------------------------------------------------------- fpcoder · 2025-02-14 18:47 Thanks for the suggestion, chucky.