Page 1 of 1

Custom Axis Label colour

Posted: Tue Aug 02, 2016 6:23 am
by 16478315
Hi,
I have a custom axis.
I add items to it using m_pChart->LeftAxis->Items->Add(Position, Value);
This works fine.
However, I would like to be able to set the colour of the labels to something other than the default. Everything I try has failed:
Did not work:
m_pChart->LeftAxis->Items->Add(Position, Value)->Format->Color = clBlue
Did not work:
TAxisItem* NewItem (m_pChart->LeftAxis->Items->Add(Position, Value));
NewItem->Format->Color = clBlue;
None of these work:
LeftAxis->LabelsFormat->Font->Color = clBlue;
LeftAxis->Items->Format->Color = clBlue;
LeftAxis->LabelsFont->Color = clBlue;

In fact the documentation does state that none of these will work with custom axes, so what does?
I am at my wits end!

Thanks
jfinch

Re: Custom Axis Label colour

Posted: Tue Aug 02, 2016 6:24 am
by 16478315
Should have stated, I am using Embarcadero® C++Builder 10.1 Berlin Version 24.0.22858.6822

Re: Custom Axis Label colour

Posted: Tue Aug 02, 2016 2:41 pm
by 10050769
Hello jfinch,

The code below changes the labels font color for me without problems:

Code: Select all

void __fastcall TForm1::FormCreate(TObject *Sender)
{
Chart1->View3D = false;
Series1->FillSampleValues();
Series2->FillSampleValues();

Chart1->CustomAxes->Items[0]->Horizontal = false;
Chart1->CustomAxes->Items[0]->LabelsFont->Color = clBlue;

Chart1->Axes->Left->StartPosition = 0;
Chart1->Axes->Left->EndPosition = 50;
Chart1->Axes->Left->LabelsFont->Color = clRed;


Chart1->CustomAxes->Items[0]->StartPosition = 50;
Chart1->CustomAxes->Items[0]->EndPosition = 100;
Series1->VertAxis = aLeftAxis;
Series2->CustomVertAxis = Chart1->CustomAxes->Items[0];

}
Could you tell us if the above code works in your end? Also, if not, could you tell us which Teechart Pro VCL/FMX are you using?

Thanks in advance

Re: Custom Axis Label colour

Posted: Wed Aug 03, 2016 12:19 am
by 16478315
Hi,
The code you posted throws:
First chance exception at $7672DAE8. Exception class EArgumentOutOfRangeException with message 'Argument out of range'.
So I could not test it out.

However I have a query about it.

You are accessing something called a CustomAxis.
I was actually adding labels using
m_pChart->Axes->Left->Items->Add

So I think my original question was incorrect.
What I need to know is how to change the colour of custom labels on an ordinary axis, not on a custom axis.

Thanks
jfinch

Re: Custom Axis Label colour

Posted: Wed Aug 03, 2016 12:20 am
by 16478315
Sorry forgot to give version: Steema TeeChart Pro VCL FMX 2016.18

Re: Custom Axis Label colour

Posted: Wed Aug 03, 2016 11:12 am
by 10050769
Hello jfinch,

Many thanks for clarify the information.

I have attached a simple example where the custom labels font color is changed. Could you tell us if it works in your end?
VCLLabelsTest_C++.zip
(59.11 KiB) Downloaded 675 times
Thanks in advance

Re: Custom Axis Label colour

Posted: Thu Aug 04, 2016 12:19 am
by 16478315
Thanks Sandra,

That example you sent does work.
However, when you run it you will notice that the left labels overlap.
In my code I have an AfterDraw function to remove overlapping labels, and it turns out that it is that function (found on one of these forums) that is causing the problem.
I cannot find where to put a color command within that.
I have attached an alteration to your code, where a button click puts it through the type of thing I have in my program.
As you will see, when button1 is pushed a different graph appears, the labels are red but overlapping.
When button2 is pushed the same graph appears, the labels do not overlap, but they are now black.

Hopefully you can tell me where I can put the color command to get the labels to go back to being red.

Thanks again for the prompt and useful help!
jfinch

Re: Custom Axis Label colour

Posted: Thu Aug 04, 2016 10:02 am
by 10050769
Hello jfinch,

Good news. After, reviewing the code you send me, we detected where is the problem, basically, is needed set the pAxisLabel font color in the CheclLeftAxisLabel method for each new custom label. I have modified the code and now works in correct way for us here.

Could you review if the attached project below works in your end?
VCLLabelsTest_C++_mod.zip
(61.37 KiB) Downloaded 590 times

Re: Custom Axis Label colour

Posted: Fri Aug 05, 2016 1:00 am
by 16478315
Thank you very much - that works!