Create a teechart dynamically

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Clara Genermont
Newbie
Newbie
Posts: 42
Joined: Mon Jun 11, 2007 12:00 am
Contact:

Create a teechart dynamically

Post by Clara Genermont » Thu Sep 25, 2008 10:14 am

Hi Narcis,

Why this code doesn't functions ?

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
  Chart1: TChart;
begin
  try
    Chart1 := TChart.Create(self);
    Chart1.Top := 0;
    Chart1.Left := 0;
    Chart1.Height := 300;
    Chart1.Width := 500;
    Chart1.RemoveAllSeries;
    Chart1.AddSeries(TBarSeries.Create(Self));
    Chart1[0].Clear;
    Chart1[0].Add(123, 'ABC', clRed);
    Chart1[0].Add(456, 'DEF', clBlue);
    Chart1[0].Add(321, 'GHI', clGreen);
    Chart1[0].Marks.Style := smsValue;
  finally
    Chart1.Free;
  end;
end;

Thank you for your help

Didou

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

Post by Narcís » Thu Sep 25, 2008 10:39 am

Hi Didou,

This is because you need to assign chart's Parent control as shown in code below. Also, freeing the created chart destroys it so you should comment this line.

Code: Select all

uses Chart, TeEngine, Series;

procedure TForm1.Button1Click(Sender: TObject);
var
  Chart1: TChart;
begin
  try
    Chart1 := TChart.Create(self);
    Chart1.Parent := self;
    Chart1.Top := 0;
    Chart1.Left := 0;
    Chart1.Height := 300;
    Chart1.Width := 500;
    Chart1.RemoveAllSeries;
    Chart1.AddSeries(TBarSeries.Create(Self));
    Chart1[0].Clear;
    Chart1[0].Add(123, 'ABC', clRed);
    Chart1[0].Add(456, 'DEF', clBlue);
    Chart1[0].Add(321, 'GHI', clGreen);
    Chart1[0].Marks.Style := smsValue;
  finally
    //Chart1.Free;
  end;
end;
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

Clara Genermont
Newbie
Newbie
Posts: 42
Joined: Mon Jun 11, 2007 12:00 am
Contact:

Post by Clara Genermont » Thu Sep 25, 2008 12:29 pm

And yet if you place a ShowMessage (Self.name)
we get well "Form1".

Why is it necessary to indicate the parent in this case?

Thank you for your reply fast

Didou

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 Sep 29, 2008 10:51 am

Hi Didou,

TChart derives from TCustomPanel, which is derived from TControl. If you have a look at TControl's Parent property in Delphi help files you'll find some information about this.
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