Page 1 of 1
Add custom control to Tchart legend
Posted: Mon Apr 07, 2014 12:52 pm
by 16868859
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
Re: Add custom control to Tchart legend
Posted: Mon Apr 07, 2014 3:20 pm
by yeray
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;
Re: Add custom control to Tchart legend
Posted: Tue Apr 08, 2014 2:34 pm
by 16868859
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.