TChart Canvas access

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Messie
Newbie
Newbie
Posts: 34
Joined: Wed Apr 13, 2005 4:00 am
Location: Goettingen, Germany

TChart Canvas access

Post by Messie » Wed Apr 11, 2007 11:54 am

Referring to the help document I tried to access the Canvas to place text there.
Description
Use the Canvas property to access all Canvas and Canvas3D properties and methods.

Canvas example

//Draws a Line between co-ordinates 50,50 (
//from Chart Panel Top, Left) to 100,100
Chart1.Canvas.MoveTo(50,50);
Chart1.Canvas.LineTo(100,100);
Unfortunately, with each new data point or running a charteditor the repaint erases all drawn and written to the canvas.
Is there any workaround?

Thanks, Messie

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Apr 11, 2007 11:59 am

Hi Messie,

Yes, you should use this code on TChart's OnAfterDraw event so the custom painting is done every time the chart is repainted.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Messie
Newbie
Newbie
Posts: 34
Joined: Wed Apr 13, 2005 4:00 am
Location: Goettingen, Germany

Post by Messie » Thu Apr 12, 2007 11:00 am

narcis wrote:Hi Messie,

Yes, you should use this code on TChart's OnAfterDraw event so the custom painting is done every time the chart is repainted.
I tried that, but I first have the problem that the chart is not displayed on the screen but printed to a printer canvas. So the AfterDraw is not hooked until the printing is done.
So I need a better way to trigger the Drawing manually than painting the graph to a dummy canvas.
Second is, that the chart.canvas.handle is changed when the OnAfterDraw event is triggered.

Code: Select all

Form := TTntForm.Create(Application);
  Graph := TChart.Create(Form);
  Graph.Parent := Form;
  Graph.OnAfterDraw := ObjectUtils.ChartAfterDraw;
  ...
  GraphHandle := Graph.Canvas.Handle;//global buffer
  Graph.PaintTo(Form.Canvas,0,0);
  ...
  PrintCanvas.Draw(0,0,graph.TeeCreateMetafile(false,rect));
  GraphHandle := Graph.Canvas.Handle; //now it's different
Does the canvas need an own reference when it is created at runtime?
I tested an example using a chart on a visible form and the canvas.handle changes again. Is the canvas recreated at each repaint?

Thanks, Ulfert

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Apr 12, 2007 11:11 am

Hi Ulfert,

Have you tried drawing directly on printer's canvas as shown in the StretchDraw example I pointed you some days ago?
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Messie
Newbie
Newbie
Posts: 34
Joined: Wed Apr 13, 2005 4:00 am
Location: Goettingen, Germany

Post by Messie » Thu Apr 12, 2007 12:23 pm

narcis wrote:Hi Ulfert,

Have you tried drawing directly on printer's canvas as shown in the StretchDraw example I pointed you some days ago?
Yes, I did but used the Canvas.draw instead due to problems with Stretchdraw an the scaling of 1/100 mm.
The drawing of the Chart itself works fine, but the additional drawing appears on the printer canvas, not on the chart canvas.

Ulfert

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Apr 12, 2007 1:05 pm

Hi Ulfert,

Something I forgot to tell you is that you can call Chart1.Draw when you want the OnAfterDraw event executed. You could try a Draw call when you want custom drawing done on TChart's canvas.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Messie
Newbie
Newbie
Posts: 34
Joined: Wed Apr 13, 2005 4:00 am
Location: Goettingen, Germany

Post by Messie » Thu Apr 12, 2007 1:40 pm

narcis wrote:Hi Ulfert,

Something I forgot to tell you is that you can call Chart1.Draw when you want the OnAfterDraw event executed. You could try a Draw call when you want custom drawing done on TChart's canvas.
Yes, that works but does not solve my problem that these additional drawings get lost on printing. Is it possible that the TeeCreateMetafile causes a repaint and the OnAfterDraw is triggered after the printout?

Ulfert

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Fri Apr 20, 2007 3:19 pm

Hi Ulfert,
I'm not sure how you are placing the custom objects on the canvas, would you be so kind to send me an small app with which I can care produce the problem here ? (you can send me it directly to pep@steema.com).

Having added the custom draw in the OnAfterDraw event you they should appear on the Canvas after you do a print using the TeeCreateMetafile.

Messie
Newbie
Newbie
Posts: 34
Joined: Wed Apr 13, 2005 4:00 am
Location: Goettingen, Germany

Post by Messie » Wed May 02, 2007 6:33 am

Hi Pep,

could you verify the problem?

Thanks, Ulfert

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Tue May 08, 2007 8:53 am

Hi Ulfert,

yes, answered directly to your mail.

Post Reply