I am doing some custom drawing on my chart control in connection with mouse movements. In other words, whenever I move mouse I am drawing some graphics on my chart.
Right now I am handling chart's OnBeforeDrawSeries and OnMouseMove.
eg. (just an example to show my apporach):
Code: Select all
procedure xxx.OnMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
LastPt.X := x;
LastPt.Y := y;
Chart.Repaint;
end;
procedure xxx.OnBeforeDrawSeries(Sender: TObject);
begin
Chart.Canvas.TextOut(LastPt.x, LastPt.Y, 'Some text');
end;
I am not drawing on canvas directly in OnMouseMove event because graphics gets messed up if Chart.Repaint is called from any other method. Therefore I just execute Chart.Repaint to start events such as BeforeDrawSeries and AfterDrawGraph and do drawing there.
Is there any better approach to do that? What about declaring new class derived from Tchart and use some protected methods? Any suggestion?
Thank you in advance.
Kind regards.