QuickReport related


Q: How can I copy one chart I have into a QuickReport Chart ?


The QRChart component has a "Chart" property which points to a normal TDBChart component. You can use the code below to assign one existing chart to a QRChart.

DELPHI CODE: 

  QRChart1.Chart.FreeAllSeries;
  QRChart1.Chart.Assign(Chart1);
  for t:=0 to Chart1.SeriesCount-1 do
        CloneChartSeries(Chart1[t]).ParentChart:=QRChart1.Chart;

CBUILDER CODE: 

 QRChart1->Chart->FreeAllSeries();
 QRChart1->Chart->Assign(Chart1);
 for (int t=0;t<=Chart1->SeriesCount()-1;t++)
    CloneChartSeries(Chart1->Series[t])->ParentChart=QRChart1->Chart;

Q: How can I create a TQRChart at run-time on a QuickReport ?


The code below does it.
It happens the QRChart automatically creates the wrapped QRDBChart if and only if you create it at design-time under Delphi (or C++ Builder 3) IDE.
Creating a QRChart at run-time does not create the sub-chart component because it expects to obtain the sub-chart when the IDE loads the DFM form.

So, you have to create a QRDBChart and set the owner to be the QRChart. The QRChart will notice this and will use the QRDBChart instance as the sub-chart property.

DELPHI CODE: 

procedure TForm1.Button1Click(Sender: TObject);
var tmp:TQRChart;
begin
  { Create the QRChart }
  tmp:=TQRChart.Create(Self);
  { Create the QRDBChart }
  With TQRDBChart.Create(tmp) do
  begin
    Parent:=TWinControl(tmp);
    Name:=TeeGetUniqueName(Owner,'QRChart');
    Title.Text.Clear;
    Title.Text.Add(tmp.ClassName);
  end;
  { add the QRChart to the QuickReport... }
  With tmp do
  begin
    ParentReport:=QuickRep1;
    Parent:=TitleBand1;
    Width:=300;
    Height:=160;
    Left:=30;
    Top:=20;
    { Create a Series and add sample values... }
    Chart.AddSeries( TBarSeries.Create(Self) );
    Chart.Series[0].FillSampleValues(7);
  end;
end;

CBUILDER CODE: 

void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
  // Create the QRChart
  TQRChart *tmp=new TQRChart(this);
  // Create the QRDBChart
  TQRDBChart *tmpQRDB=new TQRDBChart(tmp);
  tmpQRDB->Parent=tmp;
  tmpQRDB->Name=TeeGetUniqueName(tmpQRDB->Owner,"QRChart");
  tmpQRDB->Title->Text->Clear();
  tmpQRDB->Title->Text->Add(tmp->ClassName());

  // add the QRChart to the QuickReport...
  tmp->ParentReport=QuickRep1;
  tmp->Parent=TitleBand1;
  tmp->Width=300;
  tmp->Height=160;
  tmp->Left=30;
  tmp->Top=20;
  // Create a Series and add sample values...
  TBarSeries *tmpSer=new TBarSeries(this);
  tmpSer->ParentChart=tmp->Chart;
  tmpSer->FillSampleValues(7);
}

Q: How can I install TeeChart4 with new versions of QuickReport?

The following example is for Delphi4, but something very similar can be done with Delphi3 and BCB3.

  1. First, you must have TeeChart4.01PRO (trial or registered) version available.You can download it from our web site.
  2. Now install TeeChart4.01PRO (trial or registered) version. If you are using QuickReport 3.03 then this step should complete your installation. But if you are using different version of QuickReport then you must edit and recompile/reinstall the TeeQR44.dpk package. This is the package which enables you to use QuickReport and TeeChart together. Here is what you must do:

 

  1. Go to the "Component->Install packages" menu and if the "TeeChart 4.0 for QuickReport Components" is present, remove it (the "Remove" button). Also, don't forget to check the "Default" checkbox.
  2. Locate the TeeQR44.dpk package. The most probable place is TeeChart \QuickReport directory.
  3. Open the TeeQR44.dpk package.
  4. There are two folders in TeeQR44.dpk: the "Contains" and the "Requires" folder. All required files are listed in the "Requires" folder. Among them is also QRpt40.dcp compiled package (The Quick Report compiled package). This line has to be removed/replaced.
  5. Remove QRpt40.dcp package from list (the "Remove" button).
  6. Add the Quick Report compiled package you have (the "Add" button). Usually it's located in the \Lib directory.
  7. Now you are ready to install TeeQR44.dpk package. Click the compile and then the install button. Again, don't forget to check the "Default" checkbox.

Q: How can I draw some stuff on the TQRChart. It seems TQRChart does not support the OnAfterDraw event ?

You can use the TQRChart.Chart.OnAfterDraw event (see the example bellow):

DELPHI CODE:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, TeeProcs, TeEngine, Chart, DBChart, QrTee, QuickRpt;

type
 TForm1 = class(TForm)
  QRDBChart1: TQRDBChart;
  QRChart1: TQRChart;
   procedure FormCreate(Sender: TObject);
   private
    procedure MyTest(Sender: TObject);
   { Private declarations }
   public
    { Public declarations }
   end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.MyTest(Sender: TObject);
begin
  QRChart1.Chart.Canvas.TextOut(200,200,'Test');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 QRChart1.Chart.OnAfterDraw:=MyTest;
end;
end.

CBUILDER CODE:

*.H FILE:

//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
        TQuickRep *QuickRep1;
        TQRBand *TitleBand1;
        TQRDBChart *QRDBChart1;
        TQRChart *QRChart1;
        void __fastcall AfterDraw(TObject *Sender);
        void __fastcall FormCreate(TObject *Sender);
private:	// User declarations
public:		// User declarations
        __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------

*.CPP FILE: 
//---------------------------------------------------------------------------
void __fastcall TForm1::AfterDraw(TObject *Sender)
{

  QRChart1->Chart->Canvas->TextOut(200,200,"Test");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
        QRChart1->Chart->OnAfterDraw=AfterDraw;
}
//---------------------------------------------------------------------------

Q: How can I save/load chart definitions directly into a TQRChart ?

DELPHI CODE:

procedure TForm1.btnSaveClick(Sender: TObject);
begin
   SaveChartToFile(QRChart1.Chart,'c:\temp\test1.tee');
end;

procedure TForm1.btnLoadClick(Sender: TObject);
var tmp: TCustomChart;
begin
   QRChart1.Chart.Free;
   tmp:=TQRDBChart.Create(Self);
   tmp.Parent:=TWinControl(QRChart1);
   LoadChartFromFile(tmp,'c:\temp\test1.tee');
   QRChart1.Chart.Assign(tmp);
end;