iMan Biglari
iMan Biglari

Reputation: 4786

TeeChart Transparency in Delphi XE2

Is it possible to make a TeeChart's background transparent? I'm using v2011.03.32815 (the version which comes out of the box with Delphi XE2). I found a somewhat working solution here but it's not what I need. My DBCharts are inside a frame, and the background on which the charts are drawn might change. So, any ideas?

Upvotes: 0

Views: 1968

Answers (1)

Narcís Calvet
Narcís Calvet

Reputation: 7452

What about the example Yeray posted here?

This applied to a multiple chart form/panel could be something like this:

procedure TFrame3.Chart1BeforeDrawChart(Sender: TObject);
begin
  MakeChartTransparent(Chart1, Back1);
end;

procedure TFrame3.Chart2BeforeDrawChart(Sender: TObject);
begin
  MakeChartTransparent(Chart2, Back2);
end;

procedure TFrame3.Chart3BeforeDrawChart(Sender: TObject);
begin
  MakeChartTransparent(Chart3, Back3);
end;

procedure TFrame3.MakeChartTransparent(Chart: TChart; var Back: TBitmap);
begin
  if not Assigned(Back) then
  begin
    Back:=TBitmap.Create;
    Back.Width:=Chart.Width;
    Back.Height:=Chart.Height;

    Back.Canvas.CopyRect(Chart.ClientRect, (Self.Parent as TForm).Canvas, Chart.BoundsRect);
  end;

  if Chart.Color=clNone then
     Chart.Canvas.Draw(0,0,Back);
end;

procedure TFrame3.Timer1Timer(Sender: TObject);
begin
  Chart1[0].FillSampleValues();
  Chart2[0].FillSampleValues();
  Chart3[0].FillSampleValues();
end;

Note that the back bitmap needs to be initialized for every chart.

Don't forget to set your charts transparent at form's OnCreate event:

procedure TForm2.FormCreate(Sender: TObject);
begin
  Frame31.Chart1.Color:=clNone;
  Frame31.Chart2.Color:=clNone;
  Frame31.Chart3.Color:=clNone;
end;

Full project is available here.

Upvotes: 3

Related Questions