Page 1 of 1
Displaying charts on TeePreviewPanel
Posted: Wed Aug 02, 2023 11:39 am
by 16489863
Hi,
to print several charts on one page I have a form containing a TeePreviewPanel.
In my MainForm I have the following code to show the print preview:
Code: Select all
procedure TMainForm.ShowPrintPreview(Sender: TObject);
begin
Chart1.PrintProportional:=False;
Chart2.PrintProportional:=False;
Chart3.PrintProportional:=False;
Chart4.PrintProportional:=False;
Chart1.PrintMargins:=Rect(2,2,2,76);
Chart2.PrintMargins:=Rect(2,25,2,51);
Chart3.PrintMargins:=Rect(2,50,2,26);
Chart4.PrintMargins:=Rect(2,75,2,2);
with frmPrintPreview.TeePreviewPanel1 do begin
Panels.Clear;
Panels.Add(Chart1);
Panels.Add(Chart2);
Panels.Add(Chart3);
Panels.Add(Chart4);
end;
frmPrintPreview.ShowModal;
end;
When the preview form is shown only one chart is visible. Only when i move the window or change its size the charts will be displayed correctly. I have tried to call Repaint and Refresh with no success. How can I solve the problem?
A second question: How can I insert a text on top of the panel? I want to insert a title before printing and tried the following:
Code: Select all
with TeePreviewPanel1.DelphiCanvas do begin
Font.Height := 10;
Font.Color := clBlack;
TextOut(50,10,'My Title here');
end;
but the text is not visible. What is the correct code to do this?
Thank you in advance
Metek
Re: Displaying charts on TeePreviewPanel
Posted: Thu Aug 03, 2023 11:09 am
by yeray
Hello,
The following simple example seems to work fine for me here:
Code: Select all
uses Chart, Series, TeePrevi, TeePreviewPanel;
var Charts: array of TChart;
procedure TForm1.BPrintPreviewClick(Sender: TObject);
var preview: TChartPreview;
begin
Charts[0].PrintProportional:=False;
Charts[1].PrintProportional:=False;
Charts[2].PrintProportional:=False;
Charts[3].PrintProportional:=False;
Charts[0].PrintMargins:=Rect(2,2,2,76);
Charts[1].PrintMargins:=Rect(2,25,2,51);
Charts[2].PrintMargins:=Rect(2,50,2,26);
Charts[3].PrintMargins:=Rect(2,75,2,2);
preview:=TChartPreview.Create(Self);
with preview.TeePreviewPanel1 do begin
Panels.Clear;
Panels.Add(Charts[0]);
Panels.Add(Charts[1]);
Panels.Add(Charts[2]);
Panels.Add(Charts[3]);
end;
preview.ShowModal;
end;
procedure TForm1.FormCreate(Sender: TObject);
function CreateChart: TChart;
begin
Result:=TChart.Create(Self);
with Result do
begin
Parent:=Self;
Color:=clWhite;
Gradient.Visible:=False;
Walls.Back.Color:=clWhite;
Walls.Back.Gradient.Visible:=False;
Legend.Hide;
View3D:=False;
end;
Result.AddSeries(TBarSeries).FillSampleValues;
end;
var i: Integer;
begin
SetLength(Charts, 4);
for i:=0 to 3 do
begin
Charts[i]:=CreateChart;
with Charts[i] do
begin
Left:=i mod 2 * Width;
Top:=(i div 2 * Height) + Panel1.Height;
end;
end;
Width:=(Charts[0].Width*2) + 15;
Height:=(Charts[0].Height*2) + Panel1.Height + 38;
end;
- PrintPreview.png (50.22 KiB) Viewed 22528 times
Could you please modify it so we can reproduce the problem here?
Thanks in advance.
Re: Displaying charts on TeePreviewPanel
Posted: Thu Aug 03, 2023 11:17 am
by yeray
Regarding the second question, you could implement the
OnAfterDraw
of the
TeePreviewPanel1
as follows:
Code: Select all
with preview.TeePreviewPanel1 do begin
//...
OnAfterDraw:=PreviewAfterDraw;
end;
Code: Select all
procedure TForm1.PreviewAfterDraw(Sender: TObject);
begin
with TTeePreviewPanel(Sender).Canvas do
begin
Font.Height := -10;
Font.Color := clBlack;
TextOut(50, 10, 'My Title here');
end;
end;
Re: Displaying charts on TeePreviewPanel
Posted: Wed Aug 09, 2023 4:11 pm
by 16489863
Hello Yeray,
i was close to desperation to locate the problem in my application, but now I can reproduce it.
In my application each of the 4 charts is assigned to separate page of a PageControl.
If I start the application and immediately call up the print preview before all pages have been displayed once, the print preview does not work. This only happens the first time I call it up.
To demonstrate the effect, I have modified your example programm a little:
Code: Select all
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, VclTee.TeeGDIPlus, VCLTee.TeEngine,
Vcl.ExtCtrls, VCLTee.TeeProcs, VCLTee.Chart, Vcl.StdCtrls, VCLTee.Series,
VclTee.TeePrevi, Vcl.ComCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
BPrintPreview: TButton;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
TabSheet4: TTabSheet;
procedure FormCreate(Sender: TObject);
procedure BPrintPreviewClick(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
Charts: array of TChart;
implementation
{$R *.dfm}
procedure TForm1.BPrintPreviewClick(Sender: TObject);
var preview: TChartPreview;
begin
Charts[0].PrintProportional:=False;
Charts[1].PrintProportional:=False;
Charts[2].PrintProportional:=False;
Charts[3].PrintProportional:=False;
Charts[0].PrintMargins:=Rect(2,2,2,76);
Charts[1].PrintMargins:=Rect(2,25,2,51);
Charts[2].PrintMargins:=Rect(2,50,2,26);
Charts[3].PrintMargins:=Rect(2,75,2,2);
preview:=TChartPreview.Create(Self);
with preview.TeePreviewPanel1 do begin
Panels.Clear;
Panels.Add(Charts[0]);
Panels.Add(Charts[1]);
Panels.Add(Charts[2]);
Panels.Add(Charts[3]);
end;
preview.ShowModal;
preview.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
function CreateChart(aParent: TWinControl): TChart;
begin
Result:=TChart.Create(Self);
with Result do
begin
Parent:=aParent;
Color:=clWhite;
Gradient.Visible:=False;
Walls.Back.Color:=clWhite;
Walls.Back.Gradient.Visible:=False;
Legend.Hide;
View3D:=False;
end;
Result.AddSeries(TLineSeries).FillSampleValues;
end;
var i: Integer;
begin
SetLength(Charts, 4);
for i:=0 to 3 do
begin
Charts[i]:=CreateChart(PageControl1.Pages[i]);
with Charts[i] do Align := alClient;
end;
end;
end.
(The second problem (with the print title) we should perhaps discuss in a separate thread. I wanted to have the print title printed on the paper as well, not only on the preview panel)
Regards
Metek
Re: Displaying charts on TeePreviewPanel
Posted: Mon Aug 14, 2023 6:53 am
by 16489863
Does anyone have a solution or workaround for the prolem?
Re: Displaying charts on TeePreviewPanel
Posted: Mon Aug 14, 2023 11:43 am
by Marc
Hello Metek,
I'm checking what repaint method can force the render but haven't found one yet other than CopyToClipboard, which works but, as the name implies, leaves a chart on the clipboard.
ie.
Charts.CopyToClipboardBitmap;
Regards,
Marc Meumann
Re: Displaying charts on TeePreviewPanel
Posted: Thu Aug 17, 2023 6:02 am
by 16489863
Hello Marc,
thanks for the workaround, it works well.
The clipboard can then simply be deleted with Clipboard.Clear
Re: Displaying charts on TeePreviewPanel
Posted: Wed Aug 23, 2023 2:12 pm
by yeray
Hello,
As an alternative to that workaround, forcing the charts to be drawn works fine for me:
Code: Select all
procedure TForm1.BPrintPreviewClick(Sender: TObject);
var preview: TChartPreview;
i: Integer;
begin
Charts[0].PrintMargins:=Rect(2,2,2,76);
Charts[1].PrintMargins:=Rect(2,25,2,51);
Charts[2].PrintMargins:=Rect(2,50,2,26);
Charts[3].PrintMargins:=Rect(2,75,2,2);
preview:=TChartPreview.Create(Self);
with preview.TeePreviewPanel1 do begin
Panels.Clear;
for i:=0 to High(Charts) do begin
Charts[i].Draw;
Charts[i].PrintProportional:=False;
Panels.Add(Charts[i]);
end;
end;
preview.ShowModal;
preview.Free;
end;