Page 1 of 1

Custom Labels

Posted: Thu Sep 11, 2008 6:48 am
by 10550286
I've recently upgraded from Version 7 standard to Version 8 Pro, and my usage of custom labels seems to have become broken.

I'm trying to swap between tchart's automatic labelling and a different scheme of mine. It seems like the automatic/default labels are now contained within the axis items list.

What I used to do was do something like 'LeftAxis->Items->Add(50);' To get custom labels, and 'LeftAxis->Items->Clear();' to remove them and revert to tchart's automatic labelling.

Now when I make that Clear call it removes all the TChart automatic/default labels as well and I can't find a way to bring them back. I've tried fiddling with the label properties LabelStyle = talAuto;
Increment = 0; Labels = true; etc.
Nothing seems to make them come back. Has the functionality for this changed? I thought this list was normally empty and only used for my custom labels?
In the help it specifically says that the Clear() method 'Removes all custom axis label objects from list.
Axis will display all labels using default properties.'

So, at the moment I'm confused as to whether this is 'upgraded' behavior or an actual error. Does anyone know what is meant to happen here?

Posted: Fri Sep 12, 2008 9:14 am
by narcis
Hi Sam,

Custom labels should behave as you describe. Actually they work that way using v8.02 here with code below. Does it work fine for you?

Code: Select all

  Chart1.Axes.Bottom.Items.Clear;

  for i := 0 to Series1.Count - 1 do
    Chart1.Axes.Bottom.Items.Add(Series1.XValue[i], IntToStr(i));
If the problem persists, could you please send us a simple example project we can run "as-is" to reproduce the problem here?

You can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.

Posted: Mon Sep 15, 2008 1:05 am
by 10550286
Your example code produces custom labels, yes. But I don't think you understood my problem. I have no difficulty in producing custom labels - my problem is switching back to the TChart's default labels. I can't find a way to do it.
After making custom labels, how does one return to default labels? I have tried clearing the custom labels, which was how I thought it was meant to work, but that just produces an axis with no labels. I have tried fiddling with other settings, but I cannot find whatever is required.
Here is my sample code.

__fastcall TForm3::TForm3(TComponent* Owner)
: TForm(Owner)
{
Chart1->FreeAllSeries();
TLineSeries* MySeries2 = new TLineSeries(this);

MySeries2->AddXY(4,101); //Add a series
MySeries2->AddXY(5,24);

Chart1->AddSeries(MySeries2);
}
//---------------------------------------------------------------------------
// Click to make custom labels - this works fine
void __fastcall TForm3::Button2Click(TObject *Sender)
{
Chart1->Axes->Bottom->Items->Clear();
int iCount = Chart1->Series[0]->Count();

for(int i = 0; i < iCount; i++) Chart1->Axes->Bottom->Items->Add(Chart1->Series[0]->XValue,String(i));
}
//---------------------------------------------------------------------------
// Click to clear custom labels - the bottom axis now has no labels.
void __fastcall TForm3::Button1Click(TObject *Sender)
{
Chart1->Axes->Bottom->Items->Clear();
}

Posted: Mon Sep 15, 2008 8:39 am
by narcis
Hi Sam,

Thanks for the information, I misunderstood your problem. In that case you can do this:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
begin
  Chart1.Axes.Bottom.Items.Automatic:=true;
  Chart1.Refresh;
end;

Posted: Tue Sep 16, 2008 1:06 am
by 10550286
Unfortunately that doesn't work. I added that code, as below, and it just leaves me with an axis without any labels.

//---------------------------------------------------------------------------
void __fastcall TForm3::Button1Click(TObject *Sender)
{
Chart1->Axes->Bottom->Items->Clear();
Chart1->Axes->Bottom->Automatic = true;
Chart1->Refresh();
}

Posted: Tue Sep 16, 2008 7:51 am
by narcis
Hi Sam,

It's not Chart1->Axes->Bottom->Automatic what you need to set to true, it's Chart1->Axes->Bottom->Items->Automatic. This works fine for me here:

Code: Select all

void __fastcall TForm2::Button2Click(TObject *Sender)
{
	Chart1->Axes->Bottom->Items->Clear();
	Chart1->Axes->Bottom->Items->Automatic = true;
	Chart1->Refresh();
}

Posted: Tue Sep 16, 2008 8:20 am
by 10550286
It worked! Thank you for you help NarcĂ­s.