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
Add custom control to Tchart legend
Re: Add custom control to Tchart legend
Hi Kagi,
You could try to create a TComboBox in the TChart and position manually. Ie:Kai wrote:Is it possible to create a custom legend and add a custom control like a TComboBox to the legend?
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,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Add custom control to Tchart legend
Hi Yeray,
thank you for the answer.
I add also this to OnAfterDraw()
to have the new position after form resize. Then it works perfect.
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;