TeeChart 6.01 for Borland C++ 6

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

TeeChart 6.01 for Borland C++ 6

Post by Peter » Wed Jun 06, 2007 8:19 am

Is there a chance to make the chart background transparent ??

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

Post by Narcís » Wed Jun 06, 2007 9:36 am

Hi Peter,

You can try making chart's color being clNone and thus chart's background being transparent doing something like this:

cpp file:

Code: Select all

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "TeeComma"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
        Chart1->Color=clNone;
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Chart1BeforeDrawChart(TObject *Sender)
{
  Back = new Graphics::TBitmap();
  Back->Width = Chart1->Width;
  Back->Height = Chart1->Height;

  Back->Canvas->CopyRect(Chart1->ClientRect,Canvas,Chart1->BoundsRect);

  if (Chart1->Color==clNone) Chart1->Canvas->Draw(0,0,Back);
}
//---------------------------------------------------------------------------
header file:

Code: Select all

//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "TeeComma.hpp"
#include <Chart.hpp>
#include <ExtCtrls.hpp>
#include <Series.hpp>
#include <TeEngine.hpp>
#include <TeeProcs.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
        TChart *Chart1;
        TTeeCommander *TeeCommander1;
        TLineSeries *Series1;
        void __fastcall FormCreate(TObject *Sender);
        void __fastcall Chart1BeforeDrawChart(TObject *Sender);
private:	// User declarations
        Graphics::TBitmap *Back;
        TTeeBlend *Blend;

public:		// User declarations
        __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

You can also make the whole chart transparent doing something like this:

Code: Select all

void __fastcall TForm1::Chart1AfterDraw(TObject *Sender)
{
  int transparency;
  TTeeBlend *blend;
  TRect r;

  transparency=100;

  r.Left = 0;
  r.Top =0;
  r.Bottom = Chart1->Height;
  r.Right = Chart1->Width;

  blend = Chart1->Canvas->BeginBlending(r, transparency);
  Chart1->Canvas->Pen->Color = this->Color;
  Chart1->Canvas->Brush->Color = this->Color;
  Chart1->Canvas->Rectangle(r);
  Chart1->Canvas->EndBlending(blend);
}
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

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

Post by Narcís » Wed Jun 06, 2007 9:49 am

Hi Peter,

As a follow up to my previous reply, an enhancement for making the chart's background transparent is implementing OnBeforeDrawChart event like this:

Code: Select all

void __fastcall TForm1::Chart1BeforeDrawChart(TObject *Sender)
{
  if (Back==NULL)
  {
    Back = new Graphics::TBitmap();
    Back->Width = Chart1->Width;
    Back->Height = Chart1->Height;

    Back->Canvas->CopyRect(Chart1->ClientRect,Canvas,Chart1->BoundsRect);
  }

  if (Chart1->Color==clNone) Chart1->Canvas->Draw(0,0,Back);
}
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

Post Reply