[Lazarus] Hint as text over TAChart

"Leonardo M. Ramé" l.rame at griensu.com
Sat Sep 20 20:38:42 CEST 2014


Hi, I want to display the value of the point below the mouse cursor as 
text over the chart.

The way I'm trying to implement this is by first add a TChartToolSet and 
DataPointHintTool, with an onHintPosition event handler to determine the 
point value, for example:

procedure TForm1.ChartToolset1DataPointHintTool1HintPosition(
   ATool: TDataPointHintTool; var APoint: TPoint);
begin
   FmyHint := Format('O: %f, H: %f, L: %f, C: %f',
     [FOHLCArray[ATool.PointIndex].open,
     FOHLCArray[ATool.PointIndex].high,
     FOHLCArray[ATool.PointIndex].low,
     FOHLCArray[ATool.PointIndex].close]);
end;

This just set a value for a variable, in this case FMyHint. Then, to 
draw the value over the chart, I use the onAfterPaint event of TAChart:

procedure TForm1.Chart1AfterPaint(ASender: TChart);
begin
   Sender.Canvas.TextOut(10, 10, FmyHint);
end;

But this event is not called after DataPointHintToolPosition, but on 
other events, such as Form.onResize.

One question is, is this the correct way to display text over a 
TAChart?, I don't like to add a TLabel over the chart.

The second question, how can I force a call to TAChart.onAftertPaint?.

Regards,
-- 
Leonardo M. Ramé
http://leonardorame.blogspot.com




More information about the Lazarus mailing list