Chart custom graphics drawing

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
PoLabs
Newbie
Newbie
Posts: 17
Joined: Mon Sep 01, 2014 12:00 am

Chart custom graphics drawing

Post by PoLabs » Wed Jan 14, 2015 4:30 pm

Hi,

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;
At first look this method seems to be fine but it looks like it takes some time to preocess Chart.Repain and all custom graphics seems to be drawing quite slow. I checked out my methods and measured time to process and everythings looks reasonable (<1us).

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.

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Chart custom graphics drawing

Post by Yeray » Thu Jan 15, 2015 9:36 am

Hello,

This seems to work fine for me here:

Code: Select all

uses Series;

var LastPt: TPoint;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.AddSeries(TBarSeries).FillSampleValues();
end;

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  LastPt.X := x;
  LastPt.Y := y;
  Chart1.Repaint;
end;

procedure TForm1.Chart1BeforeDrawSeries(Sender: TObject);
begin
  Chart1.Canvas.TextOut(LastPt.x, LastPt.Y, 'Some text');
end;
This way you are redrawing all the chart each time the mouse is moved. This is the easiest way to go but it may be slow if you have many points in your chart needing some time for each repaint.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

PoLabs
Newbie
Newbie
Posts: 17
Joined: Mon Sep 01, 2014 12:00 am

Re: Chart custom graphics drawing

Post by PoLabs » Thu Jan 15, 2015 9:52 am

Yeah sure. I totaly forgot that all series are repainted too. I have up to 16 series with up to 4000 samples. So although my custom drawing is super fast it will always take some time to paint all 16 series. It makes sense.

Thanks for the hint and test of my code.

PoLabs
Newbie
Newbie
Posts: 17
Joined: Mon Sep 01, 2014 12:00 am

Re: Chart custom graphics drawing

Post by PoLabs » Thu Jan 15, 2015 10:23 am

Is there any performance difference in calling chart.Repaint or Chart.Invalidate? What is the difference between them chart implementation wise?

Thanks

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Chart custom graphics drawing

Post by Yeray » Thu Jan 15, 2015 10:40 am

PoLabs wrote:Is there any performance difference in calling chart.Repaint or Chart.Invalidate? What is the difference between them chart implementation wise?
The Repiant method ends calling Invalidate so there isn't much difference between them.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply