Export multiple charts to the same metafile

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
MCM
Newbie
Newbie
Posts: 4
Joined: Fri Nov 15, 2002 12:00 am
Contact:

Export multiple charts to the same metafile

Post by MCM » Wed Mar 03, 2004 5:04 pm

My application displays a vertical stack of charts which I'd like to export to a single enhanced metafile.
I've been looking at TeeCreateMetaFile and DrawToMetaCanvas but it seems like the necessary DrawRect functionality isn't supported.

.... had an idea an which answered my own question! My solution may be useful to others:


Assumes existence of GetGraphCount and GetGraph to return graphs in a stack.

function TGraphEventHandler.CreateMetafile: TMetafile;
var tmpCanvas : TMetafileCanvas;
tmp: TMetafile;
hgt, i: Integer;
graph: TChart;
begin
hgt := 0;
for i := 0 to GetGraphCount-1 do begin
graph := GetGraph(i);
if (graph <> nil) and (graph.visible) and (graph.SeriesCount <> 0) then
hgt := hgt + graph.ClientHeight;
end;
Result := TMetafile.Create;
Result.Width := GetGraph.ClientWidth;
Result.Height := hgt;
Result.Enhanced := TRUE;
tmpCanvas := TMetafileCanvas.Create(Result,0);
try
hgt := 0;
for i := GetGraphCount-1 downto 0 do begin // bottom up
graph := GetGraph(i);
if (graph <> nil) and (graph.visible) and (graph.SeriesCount <> 0) then begin
with graph do begin
tmp := TeeCreateMetaFile(True, ClientRect);
try
tmpCanvas.StretchDraw(Rect(ClientRect.Left, ClientRect.Top+Hgt, ClientRect.Right, ClientRect.Bottom+hgt), tmp);
finally
tmp.Free;
end;
hgt := hgt + ClientHeight;
end;
end;
end;
finally
tmpCanvas.Free;
end;
end;

Usage:

with CreateMetafile do try
SaveToFile(filename);
finally
Free;
end;

Post Reply