TQRChart and OnXXX Event

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
GoToXY
Newbie
Newbie
Posts: 81
Joined: Thu Apr 03, 2008 12:00 am

TQRChart and OnXXX Event

Post by GoToXY » Fri Jan 14, 2011 6:11 pm

Hi everyone and Happy New Year!

I got a problem with the TQRChart. I want to print the chart that have onBefore.../onAfter... events but it seems it is not compatible with the TQRchart Object. I tried to manipulate the TCustomChart property of the TQRChart object but im getting "Control '' has no parent windows". (this happend when i try to fillrect on the Canvas of the QRChart.Canvas)

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

Re: TQRChart and OnXXX Event

Post by Yeray » Tue Jan 18, 2011 10:41 am

Hi GoToXY,

I think that when you print the report, the positions used in the Chart event are relative to the report while when the chart is shown in the form the positions are relative to the Chart.
As a workaround, you could try using TQRImages. The procedure would be:
1) Don't use TQRChart for reports. Instead, use regular TDBChart.
2) To show/print TDBChart, first create a temporary metafile and assign it to TQRImage. The end result is TDBChart "image", displayed in report.

If you still have problems with it, please try to arrange a simple example project we can run as-is to reproduce the problem here.
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

GoToXY
Newbie
Newbie
Posts: 81
Joined: Thu Apr 03, 2008 12:00 am

Re: TQRChart and OnXXX Event

Post by GoToXY » Wed Jan 19, 2011 2:15 pm

I was using a similar approach before i could compile the QRChart ( 1 year ago) and the quality of the QRImage was less good than the QRChart. There was a lot of ajustment i had to do, to make it print correctly and some line was missing their properties (- - - or - . - . - ect...)

From what i know about the "No Parent" is that the Canvas of the Chart is not assign to something say "Visible". Ill try to find a way to correct that because i really dont want to go backward. Maybe there is something missing in the autocreate Chart of the QRChart that doesnt link well with the report form.

GoToXY
Newbie
Newbie
Posts: 81
Joined: Thu Apr 03, 2008 12:00 am

Re: TQRChart and OnXXX Event

Post by GoToXY » Wed Jan 19, 2011 2:48 pm

Oh well, im sorry. It isn't what i tough it was. When you told me to do the metafile and xfer it to the DBChart, i just check my code and i was using my old code from 1 year ago. I did embedded it so i could use it in my primary software or in my Webservice and i did forgot to assing the parent of my Chart.

Still, i would appreciate that all draw events from a regular chart (onBeforeDrawAxes, onAfterDraw etc..) be present and fonctionnal in a TQRChart. I have to draw often in the back of a chart and it could really help me out. Or maybe able use to access the Chart in the QRChart and then use those Events.

GoToXY
Newbie
Newbie
Posts: 81
Joined: Thu Apr 03, 2008 12:00 am

Re: TQRChart and OnXXX Event

Post by GoToXY » Wed Jan 19, 2011 3:07 pm

hi Yeray,
I would like to know if im doing something wrong because i got wierd result.

I have a chart that is correctly draw with a onBeforeDrawAxis event.
I used QRchart1.SetChart(MyCorrectChart); (I presume SetChart assign the chart to the QRChart (Copy))
QRchart1.Chart.onBeforeDrawAxis := MyCorrectChart.onBeforeDrawAxis;

In my onBeforeDrawAxis the Chart.ChartRect (Top and bottom) always equal 0. So my Draw never is showed.

GoToXY
Newbie
Newbie
Posts: 81
Joined: Thu Apr 03, 2008 12:00 am

Re: TQRChart and OnXXX Event

Post by GoToXY » Wed Jan 19, 2011 3:29 pm

Well, im back to Square #1. I just look at the source and it seems that TeeCreateMetaFile used in the TQRDBChart.Paint event never call any DrawEvent from the Chart. I really need it to call it so what can i do to make sure TeeCreateMetaFile use the onDrawXXX Event of the chart ?

GoToXY
Newbie
Newbie
Posts: 81
Joined: Thu Apr 03, 2008 12:00 am

Re: TQRChart and OnXXX Event

Post by GoToXY » Wed Jan 19, 2011 3:57 pm

I've changed the TQRChart.Paint proceudre from QrTee From:
procedure TQRChart.Paint;
begin
if Assigned(Chart) then
begin
Chart.AutoRepaint:=False;
try
Chart.Paint;
finally
Chart.AutoRepaint:=True;
end;
end;

if Assigned(ParentReport) then
inherited;
end;

To

procedure TQRChart.Paint;
begin
if Assigned(Chart) then
begin
Chart.AutoRepaint:=False;
try
Chart.RePaint;
finally
Chart.AutoRepaint:=True;
end;
end;

if Assigned(ParentReport) then
inherited;
end;

Now my onBeforeDrawAxis is call but my Chart.ChartRect value = (0,0,0,0) :(



A very wierd thing i found is that: dont know if it could help
QRChart1.SetChart(MyCorrectChart);
QRChart1.Chart.OnBeforeDrawAxis := MyCorrectChart.OnBeforeDrawAxis;
QRChart1.Chart.Name := 'QRChart1Chart';

Procedure TMyCorrectChart.onBeforeDrawAxis(Sender: TObject);
Begin
ShowMessage(Chart.Name); (The result is always blank)
End;

Oh Well, i just found my issue there!!! I was using Chart.name in TMyCorrectChart but Chart was a property of my TMyCorrectChart. In fact, i just modify my code a bit and its working.

Procedure TMyCorrectChart.onBeforeDrawAxis(Sender: TObject);
Var
AChart : TChart;

Begin
AChart := TChart(Sender);
ShowMessage(AChart.Name);
End;

So finally, After i did correct everything, everything seems fine. Put Back Paint in TQRChart.Paint and it still working good.

Looks like i did only disturb you. Sorry for that.

So at the End the only thing to add would be on the TQRChart.SetChart and assign the DrawEvents to the other chart. (assign doesnt seem to apply that to the drawevent) OR Giving access to the Chart of the TQRChart so we can create those event with the IDE.

Again, thanks a lot for your support.

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

Re: TQRChart and OnXXX Event

Post by Yeray » Fri Jan 21, 2011 9:42 am

Hi GoToXY,

Here it is the application I used to test it with two pdf outputs.
QRChart_Print_CustomDraw.zip
(27.59 KiB) Downloaded 668 times
I've used Cute pdf Writer to test the print output.

First, I used the Chart previewer and I saw the displacement I talked you about in my first response.
However, using the QuickReport previewer, the pdf generated looks perfect, isn't it?

So I'm still confused. I've also checked the fllowing statement at OnBeforeDrawAxes and it shows correct texts.

Code: Select all

ShowMessage(QRChart1.Name + #13#10 + QRDBChart1.Name);
And your modification suggestion in QRTee.pas makes my application not to show the chart in the form.

Maybe we are using different versions? I'm using TeeChart v2010.01 + QuickReport 5 in Delphi XE.
Or maybe I haven't understood it well. In that case, please, try to modify my project or send us a simple example project we can run as-is to reproduce the problem here.
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

GoToXY
Newbie
Newbie
Posts: 81
Joined: Thu Apr 03, 2008 12:00 am

Re: TQRChart and OnXXX Event

Post by GoToXY » Fri Jan 21, 2011 2:20 pm

Saddly i can't open your project. But i can see the PDF.

I'm using D2010 with TeeChart 8.07 and QuickReport 5.04

To make it simple (hope i will lol i can be so confused sometime), i did finally found out why it wasn't working. (Before i could compile the QRChart, i had to use a QRImage and then send my "virtual" Tchart image to that QRImage. To be able to use it in multiple project, i did a Class that included all the necessary to generate the chart and export it to a qrimage. that is what i call embedded) So, that embedded chart was my main issue of why every thing was not working well because i had a property called Chart referencing to my private var FChart. I have the habbit to always call my main TChart "Chart". So, since i can't use the IDE to create my onBeforeDrawAxis event, i did manally assign my event from my embedded class. And i code it like it was in my form (using Chart thinking it was my TQRChart, but in fact it was the property of my embedded class) So thats why when i was setting the name and all the other stuff that nothing at all was working. I know this is very very noob of my part and i am very sorry to have disturb you with that issue.
ssTQRChart.jpg
Would be nice to see the properties and event of the assigned chart
ssTQRChart.jpg (57.61 KiB) Viewed 15095 times

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

Re: TQRChart and OnXXX Event

Post by Yeray » Fri Jan 21, 2011 2:35 pm

Hi GoToXY,

Don't lament for it! I'm really glad to hear that the problem is now solved and everything is working fine.
Furthermore, if this experience can help another person getting crazy trying to find a solution... isn't it enough reason for not to regret? Thanks for sharing!
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

GoToXY
Newbie
Newbie
Posts: 81
Joined: Thu Apr 03, 2008 12:00 am

Re: TQRChart and OnXXX Event

Post by GoToXY » Fri Jan 21, 2011 2:42 pm

hehehe well ill try not the next time, but i really dont like disturbing you when you dont have anything to do with my issues.

Again and again, thanks a lot.

Last question about this thread tho.

Is is possible to add the + before the chart in the TQRChart property to see and modify the properties and events of that one directyl from the IDE ?

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

Re: TQRChart and OnXXX Event

Post by Yeray » Fri Jan 21, 2011 3:31 pm

Hi GoToXY,

When you select the QRChart you have in the form at design time, the QRChart1 (TQRChart component) is selected in the Object Inspector.
However, you can use the dropdown list in the ObjectInspector to select QRDBChart1 (TQRDBChart component), like follows:
ObjInspector.png
ObjInspector.png (6.48 KiB) Viewed 15098 times
And there you can see the Chart events at design time:
ObjInspector2.png
ObjInspector2.png (5.78 KiB) Viewed 15090 times
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

GoToXY
Newbie
Newbie
Posts: 81
Joined: Thu Apr 03, 2008 12:00 am

Re: TQRChart and OnXXX Event

Post by GoToXY » Fri Jan 21, 2011 3:39 pm

Oh hehehee well, this is something i never used before in Delphi in 15 years of use lool.

heheh thx a lot.

Post Reply