Add custom control to Tchart legend

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Kai
Newbie
Newbie
Posts: 11
Joined: Tue Apr 01, 2014 12:00 am

Add custom control to Tchart legend

Post by Kai » Mon Apr 07, 2014 12:52 pm

We are using the TeeChartStandard2014 package.

Is it possible to create a custom legend and add a custom control like a TComboBox to the legend?

Best Regards,

Kai

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Add custom control to Tchart legend

Post by Yeray » Mon Apr 07, 2014 3:20 pm

Hi Kagi,
Kai wrote:Is it possible to create a custom legend and add a custom control like a TComboBox to the legend?
You could try to create a TComboBox in the TChart and position manually. Ie:

Code: Select all

uses Series, StdCtrls;

var Chart1: TChart;
    ComboBox1: TComboBox;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  Chart1:=TChart.Create(Self);
  Chart1.Parent:=Self;
  Chart1.Align:=alClient;
  Chart1.View3D:=false;

  ComboBox1:=TComboBox.Create(Self);
  ComboBox1.Parent:=Chart1;
  ComboBox1.OnChange:=ComboBox1Change;

  for i:=0 to 4 do
  begin
    with Chart1.AddSeries(TFastLineSeries) do
    begin
      FillSampleValues;
      Title:='Series' + IntToStr(i);
    end;

    ComboBox1.AddItem(Chart1[i].Title, Chart1[i]);
  end;

  Chart1.Draw;
  ComboBox1.Left:=Chart1.Legend.Left;
  ComboBox1.Top:=Chart1.Legend.Top-25;
  ComboBox1.Width:=Chart1.Legend.Width;

  ComboBox1.ItemIndex:=0;
  ComboBox1Change(Self);
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
var i: Integer;
begin
  if (ComboBox1.ItemIndex>-1) and (ComboBox1.ItemIndex<Chart1.SeriesCount) then
  begin
    for i:=0 to Chart1.SeriesCount-1 do
      Chart1[i].Active:=false;

    Chart1[ComboBox1.ItemIndex].Active:=true;
  end;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Kai
Newbie
Newbie
Posts: 11
Joined: Tue Apr 01, 2014 12:00 am

Re: Add custom control to Tchart legend

Post by Kai » Tue Apr 08, 2014 2:34 pm

Hi Yeray,

thank you for the answer.

I add also this to OnAfterDraw()

Code: Select all

   
if ComboBox1.Visible then
begin
 ComboBox1.Left := Chart1.Legend.Left + 2;
 ComboBox1.Top := Chart1.Legend.Top + 2;
 ComboBox1.Width := Chart1.Legend.Width - 4;
 ComboBox1.BringToFront;
end;
to have the new position after form resize. Then it works perfect.

Post Reply