Page 1 of 1

TeeChart 6.01 for Borland C++ 6

Posted: Wed Jun 06, 2007 8:19 am
by 8438583
Is there a chance to make the chart background transparent ??

Posted: Wed Jun 06, 2007 9:36 am
by narcis
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);
}

Posted: Wed Jun 06, 2007 9:49 am
by narcis
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);
}