I'm trying to position a legend on the right. I've tried setting the alignment property so that I can specify via just setting the rightmost edge, but that doesn't seem to work. Is this a bug?
So instead I've been trying to do something like:
Chart1->Legend->Left = Chart1->Width - Chart1->Legend->Width - 2;
Unfortunately, the reported Chart1->Legend->Width is frequently erroneous, so the legend can shift all over the place, despite not necessarily changing size. To reproduce the erroneous width reporting, it seems related to toggling either series visibility, or the ShowInLegend property of a series (which can change the legend width, but it is still reported incorrectly).
See attached picture. I produced this by :
Code: Select all
__fastcall TFormMain::TFormMain(TComponent* Owner)
: TForm(Owner)
{
Chart1->AddSeries(new TLineSeries(Chart1));
Chart1->Series[0]->AddXY(1,1);
Chart1->Series[0]->AddXY(2,2);
Chart1->AddSeries(new TLineSeries(Chart1));
Chart1->Series[1]->AddXY(3,3);
Chart1->Series[1]->AddXY(4,4);
Chart1->Legend->Visible = true;
Label1->Caption = "";
Toggler = false;
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::TScreenUpdateTimer(TObject *Sender)
{
Toggler = !Toggler;
Chart1->Series[0]->Visible = Toggler;
//Use legend width to position the legend with respect to the right boundary
Chart1->Legend->Left = Chart1->Width - Chart1->Legend->Width - 2;
AnsiString Message = Label1->Caption;
Message += AnsiString(_T("Reported Legend Width = ")) + AnsiString(Chart1->Legend->Width) + _T("\n");
Label1->Caption = Message;
}