Page 1 of 1

TChart Canvas access

Posted: Wed Apr 11, 2007 11:54 am
by 9236620
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

Posted: Wed Apr 11, 2007 11:59 am
by narcis
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.

Posted: Thu Apr 12, 2007 11:00 am
by 9236620
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

Posted: Thu Apr 12, 2007 11:11 am
by narcis
Hi Ulfert,

Have you tried drawing directly on printer's canvas as shown in the StretchDraw example I pointed you some days ago?

Posted: Thu Apr 12, 2007 12:23 pm
by 9236620
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

Posted: Thu Apr 12, 2007 1:05 pm
by narcis
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.

Posted: Thu Apr 12, 2007 1:40 pm
by 9236620
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

Posted: Fri Apr 20, 2007 3:19 pm
by Pep
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.

Posted: Wed May 02, 2007 6:33 am
by 9236620
Hi Pep,

could you verify the problem?

Thanks, Ulfert

Posted: Tue May 08, 2007 8:53 am
by Pep
Hi Ulfert,

yes, answered directly to your mail.