Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Multi-Page Charts with TeeChart Pro

edited September 2004 in General
I am trying to create multiple page charts with TeeChart Pro. By setting
MaxPointPerPage in TChart, it creates multiple pages of the chart but only
the first page appears in TppReport. I assume that there should be an event
handler in TChart to tell RB to create a new page, but haven't found the
right combination. What is the best way to handle this?

ReportBuilder 7.04B2
TeeChart Pro 7.0

Comments

  • edited September 2004
    > I am trying to create multiple page charts with TeeChart Pro. By setting
    event

    RB has TChart create a WMF file of the chart--paging is not directly
    supported in the relationship with RB & TChart. What you could do is create

    1) a detail JIT pipeline for the chart using an image field;
    2) put a TDBImage in the report;
    3) In the OnGetImage (or something like that) use the TChart in your
    application and create an image WMF of the chart.

    I've done this quite extensively in my application (without the paging) so
    that I don't have 2 copies of a TChart (one in my app and one in the report)
    and only have to update one at a time. Reply if you need more info on any of
    these steps.
  • edited September 2004

    create
    report)
    of
    I think I follow what you are saying; I will give it a try.
  • edited September 2004
    > RB has TChart create a WMF file of the chart--paging is not directly
    create
    report)
    of
    I now have the following:

    1) Form (ChtFrm) with TChart that correctly shows the multi-page chart using
    a TChartPageNavigator. The form also has a button to launch printing the
    TppReport in 2). The button also sets the JITPipeLine.RecordCount =
    Chart.NumPages.

    2) TppReport (Chart) with TDBImage in the detail band. The data pipeline is
    set to a TJITPipeline (RB_ChtPL).

    3) The TDBImage.OnGetPicture event handler has the following:

    procedure TDM.ppDBImage1GetPicture(Sender: TObject; aPicture: TPicture);
    var
    Rect : TRect;
    begin
    Rect.Left := 0;
    Rect.Right := Screen.Width;
    Rect.Top := 0;
    Rect.Bottom := Screen.Height;
    ChtFrm.Chart.Page := RB_ChtPL.RecordIndex;
    aPicture.Metafile := ChtFrm.Chart.TeeCreateMetafile(false,Rect);
    end;

    4) Printing the TppReport gives the normal RB preview screen which displays
    the first page and shows the correct number of pages in the "tree".
    Attempting to advance to the 2nd page does nothing; the display is always of
    the first page of the chart. Printing gives as many copies of the first page
    as the number of pages in the chart.

    Do I have the metafile creation in the wrong event? Is the RecordIndex being
    used correctly? Is there a better approach?

    TIA,
    Tom
  • edited September 2004
    > 3) The TDBImage.OnGetPicture event handler has the following:

    I would use a TppImage, and I think your method creates a pretty big memory
    leak.



    being

    I don't know--try creating a small example and seeing how it works. I am
    pretty busy right now or else I would post an example--maybe I will have
    time tomorrow--I will try.

    Ed Dressel
  • edited September 2004
    > I would use a TppImage, and I think your method creates a pretty big
    memory

    Changed the TppDBImage to TppImage and released handle.

    procedure TDM.ppImage1Print(Sender: TObject);
    var
    Rect : TRect;
    begin
    Rect.Left := 0;
    Rect.Right := Screen.Width;
    Rect.Top := 0;
    Rect.Bottom := Screen.Height;
    ChtFrm.Chart.Page := RB_ChtPL.RecordIndex;
    ppImage1.Picture.Metafile.ReleaseHandle;
    ppImage1.Picture.Metafile := ChtFrm.Chart.TeeCreateMetafile(false,Rect);
    end;

    The basic problem I was seeing was solved by adding the number of pages to
    the PipeLine properties

    RB_ChtPL.RecordCount := Chart.NumPages;
    RB_ChtPL.RangeEndCount := Chart.NumPages;
    RB_Cht.Print;

    in the event handler launching the ReportBuilder print.
  • edited September 2004
    > Rect.Left := 0;

    use the TRect from the TppImage, not the screen, otherwise it will skew. I
    have mine in several pieces for implementation reasons, but here are some
    code snippets:

    procedure TfrmPrint.ImagePrint(Sender: TObject);
    var
    lRG: TReportGraphic;
    lImg: TppImage;
    lLst: TReportGraphicList;
    begin
    assert(sender is TppImage);
    lLst := TReportGraphicList.Create;
    try
    lImg := TppImage(sender);
    lRG := TReportGraphic.Create(lImg.UserName, {Config.Reports.AutoScale,}
    lImg);
    lRG.Rect := Rect(1, 1, Trunc(lImg.spWidth), Trunc(lImg.spHeight));
    lLst.Add(lRG);
    FActiveWindow.GetGraphics(lLst);
    lImg.Picture.Metafile.Assign(lLst[0].Metafile);
    finally
    lLst.Free;
    end;
    end;

    then in the assigning a metafile in my code I create a new chart so that I
    don't skew it::

    procedure AssignChartToMetafile(aChart: TChart; aReportGraphic:
    TReportGraphic);
    var
    lMS: TMemoryStream;
    lCustomChart: TCustomChart;
    I: Integer;
    lMetafile: TMetafile;
    lRect: TRect;
    lChart : TChart;
    begin
    lChart := TChart.Create(nil);
    lMS := TMemoryStream.Create;
    try
    lChart.Assign(aChart);

    SaveChartToStream(aChart, lMS, True);

    lMS.Position := 0;

    lCustomChart := TCustomChart(lChart);
    LoadChartFromStream(lCustomChart, lMS);
    lChart := TChart(lCustomChart);

    for I :=0 to lChart.SeriesCount-1 do
    begin
    lChart.Series[I].OnGetMarkText := aChart.Series[I].OnGetMarkText;
    if (lChart.Series[I] is TPieSeries) then
    TPieSeries(lChart.Series[I]).Circled := True;
    end;

    lChart.OnGetAxisLabel := aChart.OnGetAxisLabel;
    lChart.OnBeforeDrawSeries := aChart.OnBeforeDrawSeries;
    lChart.Gradient.Visible := False;
    lChart.Color := clWhite;
    lChart.BevelOuter := bvNone;


    lRect := aReportGraphic.Rect;

    lMetafile := lChart.TeeCreateMetafile(False, lRect);
    try
    aReportGraphic.Metafile.Assign(lMetafile);
    finally
    lMetafile.Free;
    end;
    finally
    lMS.Free;
    lChart.Free;
    end;
    end;

    HTH,
    Ed Dressel
    Team DM
  • edited September 2004
    Thank you very much for your help.

    Tom
This discussion has been closed.