Export graphic : How to include overlay components?

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
moelski
Advanced
Posts: 212
Joined: Mon Apr 23, 2007 12:00 am
Location: Germany
Contact:

Export graphic : How to include overlay components?

Post by moelski » Fri May 04, 2007 11:37 am

Hi !

In our software we use two additional component which lay over the chart. The first one is a simple multiline label which shows some text informations und the other component is wptools (a powerfull RTF editor).

If I open the Chart editor for export the chart to a graphic file or copy it to the clipboard, this additional component are not included in the clipboard copy and the exported file formats.

Is there a way to include this additional components in the export?

With our current chart engine we use code like this to copy to clipboard:

Code: Select all

procedure TForm1.Button5Click(Sender: TObject);
var
  bmp:      TBitmap;
  _Text1:   String;
  _Text2:   String;
  _Breite:  Integer;
begin
//  Snooze(200);
  bmp:=TBitmap.Create;
  bmp.PixelFormat := pf32bit;  // 16Mio Farben   siehe Hilfe: PixelFormat

  bmp.Width       := Form1.Chart1.Width;
  bmp.Height      := Form1.Chart1.Height + 15;

  bmp.Canvas.CopyRect(Bounds(0,0,bmp.Width, bmp.Height - 15),
    Form1.Chart1.Canvas, Form1.Chart1.ClientRect);

  _Text1 := 'Datum: ' + DateToStr(Now) + '    Zeit: ' + TimeToStr(Now);
  _Text2 := 'www.LogView.info';
  bmp.Canvas.Pen.Color := clBlack;
  bmp.Canvas.Font.Style := [fsBold];
  _Breite := bmp.Canvas.TextWidth(_Text2);
  bmp.Canvas.TextOut((Form1.Grafik.Width - _Breite - 2), bmp.Height - 14, _Text2);
  bmp.Canvas.Font.Style := [];
  bmp.Canvas.TextOut(0, bmp.Height - 14, _Text1);

  //Copy the bitmap to the clipboard
  clipboard.assign(bmp);

  bmp.Free;
end;
But this won´t work because TeeChart uses Canvas3d instead of canvas.

Any help about this?[/quote]

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Mon May 07, 2007 6:41 pm

Hi Greetz,
using the following code should do the trick :

bmp.Canvas.CopyRect(Bounds(0,0,bmp.Width, bmp.Height - 15),
Form1.Chart1.Canvas.ReferenceCanvas, Form1.Chart1.ClientRect);

moelski
Advanced
Posts: 212
Joined: Mon Apr 23, 2007 12:00 am
Location: Germany
Contact:

Post by moelski » Tue May 08, 2007 12:57 pm

Hi Pep,

thanks for the code. That works great.

Now I have one last question about this stuff ...
I want to use the build in export functions from TeeChart :wink: They are offer much more formats and flexibility then my bmp export.

Is there a way to export the chart with the added components with the TeeChart export functions? I want to build my own export dialog so it would be great if you could give me an example how to do this.

Because we add additional text to the bottom of the chart, would it be a good idea to use the produced bmp and export it with the TeeChart functions? Finally it should look like this here:

Code: Select all

procedure TForm1.Button5Click(Sender: TObject); 
var 
  bmp:      TBitmap; 
  _Text1:   String; 
  _Text2:   String; 
  _Breite:  Integer; 
begin 
//  Snooze(200); 
  bmp:=TBitmap.Create; 
  bmp.PixelFormat := pf32bit;  // 16Mio Farben   siehe Hilfe: PixelFormat 

  bmp.Width       := Form1.Chart1.Width; 
  bmp.Height      := Form1.Chart1.Height + 15; 

  bmp.Canvas.CopyRect(Bounds(0,0,bmp.Width, bmp.Height - 15), 
Form1.Chart1.Canvas.ReferenceCanvas, Form1.Chart1.ClientRect);

  _Text1 := 'Datum: ' + DateToStr(Now) + '    Zeit: ' + TimeToStr(Now); 
  _Text2 := 'www.LogView.info'; 
  bmp.Canvas.Pen.Color := clBlack; 
  bmp.Canvas.Font.Style := [fsBold]; 
  _Breite := bmp.Canvas.TextWidth(_Text2); 
  bmp.Canvas.TextOut((Form1.Chart1.Width - _Breite - 2), bmp.Height - 14, _Text2); 
  bmp.Canvas.Font.Style := []; 
  bmp.Canvas.TextOut(0, bmp.Height - 14, _Text1); 

  //export bmp with TeeChart function
  export to bmp, jpg, png, ......

  bmp.Free; 
end;

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Fri May 11, 2007 4:32 pm

Hi Dominik,

you can use similar code to the following :

Code: Select all

uses GIFImage,Teegif, TeeJpeg, jpeg;

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  bmp: TBitmap;
  gif: TGIFImage;
  jpg: TJPEGImage;

  _Text1:   String;
  _Text2:   String;
  _Breite:  Integer;
begin
//  Snooze(200);
  bmp:=TBitmap.Create;
  bmp.PixelFormat := pf32bit;  // 16Mio Farben   siehe Hilfe: PixelFormat

  bmp.Width       := Form1.Chart1.Width;
  bmp.Height      := Form1.Chart1.Height + 15;

  bmp.Canvas.CopyRect(Bounds(0,0,bmp.Width, bmp.Height - 15),
    Form1.Chart1.Canvas.ReferenceCanvas, Form1.Chart1.ClientRect);

  bmp.Canvas.Pen.Color := clBlack;
  bmp.Canvas.Font.Style := [fsBold];
  _Breite := bmp.Canvas.TextWidth(_Text2);
  bmp.Canvas.TextOut((Form1.Chart1.Width - _Breite - 2), bmp.Height - 14, _Text2);
  bmp.Canvas.Font.Style := [];
  bmp.Canvas.TextOut(0, bmp.Height - 14, _Text1);

  //export bmp with TeeChart function
  //  export to bmp, jpg, png, ......

  try
    // bmp
    bmp.SaveToFile('e:\temp\bmpChart.bmp');

    // gif
    gif := TGifImage.Create;
    gif.Assign(bmp);
    gif.SaveToFile('e:\temp\gifChart.gif');

    // jpg
    jpg:=TjpegImage.Create;
    jpg.Assign(bmp);
    jpg.SaveToFile('e:\temp\jpgChart.jpg');

  finally
    bmp.Free;
    gif.Free;
    jpg.Free;
  end;

end;

moelski
Advanced
Posts: 212
Joined: Mon Apr 23, 2007 12:00 am
Location: Germany
Contact:

Post by moelski » Sat May 19, 2007 3:45 am

Hi Pep,

well that´s not exactly what I want to do.

This is what I want to do:
- Write / design my own export dialog with the formats Metafile, BMP, PCX, JPEG, PDF, PGN, GIF, VML, SVG and Postscript. (all formats that TChart 7 offers).
- Using the export settings for each format (like in your export dialog)
- add the additional text below the exported chart (look at my code I posted above)

Your code only saves a BMP, GIF, JPEG without the possibility for adjust the settings. And there are a lot of formats mising.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon May 21, 2007 7:35 am

Hi Dominik,

Then I'd suggest you to do the custom drawing on TeeChart's canvas like told in Tutorial 13 - Custom drawing on the Chart Panel.

For other exporting formats please have a look at the examples at All Features\Welcome!\Exporting in the features demo. Regarding the exporting options, if you don't know how some properties can be implemented try using the right-top "?" button for context help. This will show you the name of the property.

Tutorials and features demo can be found at TeeChart's program group created by the binary installers.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

moelski
Advanced
Posts: 212
Joined: Mon Apr 23, 2007 12:00 am
Location: Germany
Contact:

Post by moelski » Mon May 21, 2007 2:40 pm

Hi Narcís,

thx for the help. I will have a look and let you know if I get it working.

Post Reply