Multiple TQRCharts in QuickReport

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
okfoods
Newbie
Newbie
Posts: 16
Joined: Wed Dec 28, 2005 12:00 am
Location: Fort Smith, Arkansas USA

Multiple TQRCharts in QuickReport

Post by okfoods » Wed Dec 06, 2006 10:30 pm

I am trying to print Multiple tqrcharts on a quickreport. The problem is after the first chart prints, the rest of the reports won't show a line series on them. The first report shows up with its correct Tlineseries, and then from there on the rest of the charts show up but the Tlineseries dosen't.
This is very strange. Anyone have any ideas. code below.
Can you even print multiple Tqrcharts per quickreport?


procedure TfrmDailySPCPrompt.btnOkClick(Sender: TObject);
begin
BuildReports;
frmDailySPCReport.qrDailySPCReport.Preview;
end;

procedure TfrmDailySPCPrompt.BuildReports;
Const
SPCChart =
'Select '#13#10+
' CompletedTestsMaster.TestDate , '#13#10+
' Coalesce((Select avg(Cast(CompletedTestsDetail.TestResult as Float)) '#13#10+
' from CompletedTestsDetail (Nolock) '#13#10+
' Where CompletedTestsMaster.CompletedTestsMasterKey = '#13#10+
' CompletedTestsDetail.CompletedTestsMasterKey And '#13#10+
' CompletedTestsDetail.TestKey = %TESTKEY% '#13#10+
' And CompletedTestsDetail.TestResult Is Not Null '#13#10+
' And CompletedTestsDetail.TestResult <> '''' '#13#10+
' ),0) as AVGTestResult, '#13#10+
' Coalesce((Select Max(Cast(CompletedTestsDetail.TestResult as Float)) '#13#10+
' from CompletedTestsDetail (Nolock) '#13#10+
' Where CompletedTestsMaster.CompletedTestsMasterKey = '#13#10+
' CompletedTestsDetail.CompletedTestsMasterKey And '#13#10+
' CompletedTestsDetail.TestKey = %TESTKEY% '#13#10+
' And CompletedTestsDetail.TestResult Is Not Null '#13#10+
' And CompletedTestsDetail.TestResult <> '''' '#13#10+
' ),0) as MaxTestResult, '#13#10+
' Coalesce((Select Min(Cast(CompletedTestsDetail.TestResult as Float)) '#13#10+
' from CompletedTestsDetail (Nolock) '#13#10+
' Where CompletedTestsMaster.CompletedTestsMasterKey = '#13#10+
' CompletedTestsDetail.CompletedTestsMasterKey And '#13#10+
' CompletedTestsDetail.TestKey = %TESTKEY% '#13#10+
' And CompletedTestsDetail.TestResult Is Not Null '#13#10+
' And CompletedTestsDetail.TestResult <> '''' '#13#10+
' ),0) as MinTestResult, '#13#10+
' Coalesce((Select Count(*) '#13#10+
' from CompletedTestsDetail (Nolock) '#13#10+
' Where CompletedTestsMaster.CompletedTestsMasterKey = '#13#10+
' CompletedTestsDetail.CompletedTestsMasterKey And '#13#10+
' CompletedTestsDetail.TestKey = %TESTKEY% '#13#10+
' And CompletedTestsDetail.TestResult Is Not Null '#13#10+
' And CompletedTestsDetail.TestResult <> '''' '#13#10+
' ),0) as Occurs '#13#10+
'From CompletedTestsMaster (Nolock) '#13#10+
'Where CompletedTestsMaster.Plant = %PLANT% '#13#10+
' And CompletedTestsMaster.ProductCode = %PRODUCT% '#13#10+
' and CompletedTestsMaster.ProcessKey = %PROCESSKEY% '#13#10+
' And CompletedTestsMaster.ProductionDate = %PRODDATE% '#13#10+
' Order by '#13#10+
' CompletedTestsMaster.TestDate ';
Var
// ReportForm : TfrmDailySPCReport;
Spc : TqrChart;
SpcDb : TQRDBChart;
NumberOfProducts : Integer;
i : Integer;
s : String;
tmpMinRange : Double;
tmpMaxRange : Double;
tmpIncrement : Double;
tmpXBar : Double;
tmpCount : Integer;
changeColor : TColor;
holdShift : Integer;
shiftCount : Integer;
StartCounter : Integer;
FirstTime : Boolean;
DataLineSeries,
XBarLineSeries,
RBarLineSeries,
RBarDataLineSeries,
RBarUpperLineSeries,
RBarLowerLineSeries : TLineSeries;
XBarLowerPointSeries,XBarUpperPointSeries : TPointSeries;

Begin
frmDailySPCReport := TfrmDailySPCReport.Create(Self);
aqrySPCTOChart.Parameters.ParamByName('ProductionDate').Value := Trunc(dtpProductionDate.Date);
aqrySPCTOChart.Parameters.ParamByName('Plant').Value := Integer(cbPlant.Items.Objects[cbPlant.ItemIndex]);

//***********************************************************************************
//Query brings back all of the product spc testkeys that pertained to the prompt.
//***********************************************************************************
aqrySPCTOChart.Open;
aqrySPCTOChart.First;
FirstTime := True;
While (not aqrySPCToChart.Eof) do
Begin
s := StringReplace(SPCCHart, '%TESTKEY%',aqrySPCTOChart.FieldByName('TestKey').Value , [rfIgnoreCase, rfReplaceAll]);
s := StringReplace(s,'%PLANT%', aqrySPCToChart.FieldByName('Plant').Value ,[rfIgnoreCase, rfReplaceAll]);
s := StringReplace(s,'%PRODUCT%',aqrySPCToChart.FieldByName('ProductCode').Value ,[rfIgnoreCase, rfReplaceAll]);
s := StringReplace(s,'%PROCESSKEY%', aqrySPCToChart.FieldByName('ProcessKey').Value,[rfIgnoreCase, rfReplaceAll]);
s := StringReplace(s,'%PRODDATE%', quotedStr(DateToStr(Trunc(dtpProductionDate.date))),[rfIgnoreCase, rfReplaceAll]);

//************create the chart and dbchart object ***********************************
spc := TQRChart.Create(Self);
spcDb := TQRDBChart.Create(spc);
spcdb.Parent:=TWinControl(spc);
spcdb.Title.Text.Clear;
spcdb.Title.Caption := (aqrySPCToChart.FieldByName('ProductCode').asString + ' ' + aqrySPCToChart.FieldByName('SpcDescription').AsString);
if FirstTime then
Begin
Startcounter := 20;
FirstTime := False;
End
Else
Begin
Startcounter := Startcounter + 400;
End;

Spc.Width :=600;
spc.Height :=400;
spc.Left :=30;
spc.Top :=startCounter;

XBarLowerPointSeries := TPointSeries.Create( Self );
XBarUpperPointSeries := TPointSeries.Create( Self );
DataLineSeries := TLineSeries.Create(frmDailySPCReport);
XBarLineSeries := TLineSeries.Create( Self );
DataLineSeries.Clear;
XBarLineSeries.Clear;
XBarLowerPointSeries.Clear;
XBarUpperPointSeries.Clear;
If spcdb.LeftAxis.Maximum < 0 Then
Begin
spcdb.LeftAxis.Maximum := 0;
spcdb.LeftAxis.Minimum := 0;
End
Else
Begin
spcdb.LeftAxis.Minimum := 0;
spcdb.LeftAxis.Maximum := 0;
End;
tmpStartDate := Date() - 700;
tmpEndDate := Date() + 700;
tmpCount := 0;

tmpMinRange := aqrySPCToChart.FieldByName('RangeMin').Value;
tmpMaxRange := aqrySPCToChart.FieldByName('RangeMax').Value;
tmpIncrement := aqrySPCToChart.FieldByName('StdDeviation').AsFloat;
tmpXbar := aqrySPCToChart.FieldByName('Target').AsFloat;

spcdb.LeftAxis.Automatic := False;
spcdb.LeftAxis.Maximum := tmpXBar + (tmpIncrement * 6);
spcdb.LeftAxis.Minimum := tmpXBar - (tmpIncrement * 6);
DataLineSeries.Clear ;

frmDailySPCReport.aqrySPCChart.Sql.Add(s);
frmDailySPCReport.aqrySPCChart.Open;
frmDailySPCReport.aqrySPCChart.First;
changeColor := clBlue;
Shiftcount := 0;
While Not frmDailySPCReport.aqrySPCChart.Eof Do
Begin
DataLineSeries.ColorEachPoint := true;
DataLineSeries.AddXY(frmDailySPCReport.aqrySPCChart.FieldByName('TestDate').AsDateTime,
frmDailySPCReport.aqrySPCChart.FieldByName('AVGTestResult').Value,'',clRed);
frmDailySPCReport.aqrySPCChart.Next;
End;
DataLineSeries.Marks.Style := smsValue;
DataLineSeries.SHowInLegend := False;
DataLineSeries.Title := 'Data';
DataLineSeries.Marks.Transparent := True;
DataLineSeries.Marks.Font.Color := clBlack;
DataLineSeries.Marks.Font.Size :=12;
DataLineSeries.Depth := 3;
DataLineSeries.ValueFormat := '#,##0.#';
spcdb.LeftAxis.LabelsFont.Size := 12;
spcdb.LeftAxis.TitleSize := 2 ;
XBarLineSeries.XValues.DateTime:=True;
DataLineSeries.XValues.DateTime:=True;
XbarLowerPointSeries.XValues.DateTIme:= True;
XbarUpperPointSeries.XValues.DateTIme:= True;
spcdb.BottomAxis.DateTimeFormat := 'hh:mm';
spcdb.bottomaxis.LabelsAngle := 90;
spcdb.bottomaxis.Title.Caption := '';
spcdb.BottomAxis.LabelsFont.Size := 8;
spcdb.Chart3DPercent := 1;
spc.ParentReport := frmDailySPCReport.qrDailySPCReport;
spc.Parent := frmDailySPCReport.DetailBand;
Spcdb.AddSeries(DataLineSeries);
aqrySPCTOChart.Next;
I := I + 1;
End;
End;

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

Post by Pep » Tue Dec 12, 2006 8:52 am

Hi,

I think the problem could be that you only use one TQRChart component to assign the data for each page, this could be the problem, in this way only the last returned data will be displayed. I'm not sure about this as I've not test it, I'll test it here just to be sure and will let you know something about.
As a workaround, you could try using TQRImages to show the Charts with data in the pages of the report. The procedure is more less simple:

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.

I think there is an example of this approach available at our FAQ pages.

Post Reply