[Lazarus] TAChart with transparent background

Roberto P. padovani.r at gmail.com
Thu Sep 4 01:08:54 CEST 2014


Thank  you very much.
I need a background image, therefore as soon as I am back at the office
I'll try your code.
Thank you again!

R#


2014-09-02 18:18 GMT+02:00 Werner Pamler <werner.pamler at freenet.de>:

> It is not fully clear to me what you mean by "a chart with transparent
> background". Do you want to see the form underneath the chart? I fear this
> is not easily possible. Or do you want to have a background image in the
> chart? For the latter case this code is working fine with me:
>
> type
>   TForm1 = class(TForm)
>     Chart1: TChart;
>     procedure Chart1BeforeDrawBackground(ASender: TChart; ACanvas:
> TCanvas;
>       const ARect: TRect; var ADoDefaultDrawing: Boolean);
>     procedure Chart1BeforeDrawBackWall(ASender: TChart; ACanvas: TCanvas;
>       const ARect: TRect; var ADoDefaultDrawing: Boolean);
>     procedure FormCreate(Sender: TObject);
>     procedure FormDestroy(Sender: TObject);
>   private
>     { private declarations }
>     FBackImage: TPicture;
>   public
>     { public declarations }
>   end;
> ....
> procedure TForm1.Chart1BeforeDrawBackWall(ASender: TChart; ACanvas:
> TCanvas;
>   const ARect: TRect; var ADoDefaultDrawing: Boolean);
> begin
>   ADoDefaultDrawing := false;
>   ACanvas.StretchDraw(ARect, FBackImage.Graphic);
> end;
>
> procedure TForm1.Chart1BeforeDrawBackground(ASender: TChart; ACanvas:
> TCanvas;
>   const ARect: TRect; var ADoDefaultDrawing: Boolean);
> begin
>   ACanvas.GradientFill(ARect, clSkyBlue, clWhite, gdVertical);
>   ADoDefaultDrawing := false;
> end;
>
> procedure TForm1.FormCreate(Sender: TObject);
> begin
>   FBackImage := TPicture.Create;
>   FBackImage.LoadFromFile('C:\lazarus-svn\images\splash_logo.png');
>   // please adapt this path to your lazarus installation
> end;
>
> procedure TForm1.FormDestroy(Sender: TObject);
> begin
>   FBackImage.Free;
> end;
>
> The basic idea is to assign a handler to the chart events
> OnBeforeDrawBackWall or OnBeforeDrawBackground and disable the default
> background painting by setting ADoDefaultDrawing to false. The first event
> replaces painting of the area enclosed by the chart's frame ("Back wall"),
> the other one replaces painting of the entire chart background. Above
> example paints the Lazarus splash-logo as BackWall and a gradient as
> background.
>
> Maybe I'll once write a tutorial on this topic...
>
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140904/5a09708d/attachment-0003.html>


More information about the Lazarus mailing list