How To…Chart As Image

Question

“How do I show a TeeChart created on a form as an image on a report?”

Solution

Use the TeeChart routine TeeCreateMetafile to export the chart to an image then assign it to a TppImage on a report.

Download: ChartAsImage.zip

Sample Delphi code:

procedure TForm1.Button1Click(Sender: TObject);
var
  lMetaFile: TMetaFile;
  lRect: TRect;
begin

  lRect.Left := 0;
  lRect.Top := 0;
  lRect.Right := ppImage1.spWidth;
  lRect.Bottom := ppImage1.spHeight;

  //Create a metafile from the chart
  lMetaFile := Chart1.TeeCreateMetafile(True, lRect);

  //Assign the metafile to a TppImage component
  ppImage1.Picture.Metafile.Assign(lMetaFile);

  ppReport1.Print;

  lMetaFile.Free;

end;