Page 1 of 1

Conditional Color Axis Label Color

Posted: Thu Dec 09, 2010 4:22 pm
by 10546565
I have a user's request to change the color of an axis label based on the value that the label represents.

I tried the following code:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Series1.FillSampleValues(20);
  Series2.FillSampleValues(20);
  Chart1.BottomAxis.OnDrawLabel := DrawBottomAxis;
end;

procedure TForm1.DrawBottomAxis(Sender:TChartAxis; var X,Y,Z:Integer; var Text:String;
  var DrawLabel:Boolean);
var
  lValue: Integer;
begin
  lValue := StrToIntDef(Text, -1);
  if lValue < 0 then
    Sender.LabelsFont.Color := clRed
  else
  if ((lValue mod 2) = 1) then
    Sender.LabelsFont.Color := clGreen
  else
    Sender.LabelsFont.Color := clYellow;
end;
but it didn't change the font colors--they are always black.

How can I change individual axis label font colors?

Thank you,

Ed Dressel

Re: Conditional Color Axis Label Color

Posted: Fri Dec 10, 2010 3:56 am
by 9244525
Maybe this thread is relevant for you:
http://www.teechart.net/support/viewtop ... =3&t=11883

Re: Conditional Color Axis Label Color

Posted: Fri Dec 10, 2010 7:07 pm
by 10546565
Thanks. That works.

I was looking at the source and saw that a TList was used (rather than a TObjectList) so I assumed calling .Clear would not free the objects. I see that you implemented your own Clear method and freed the objects. Just curious, why wasn't a TObjectList used rather than a TList?

Thank you,

Ed Dressel

Re: Conditional Color Axis Label Color

Posted: Fri Dec 10, 2010 8:23 pm
by 10546565
In testing, when adding labels, the 'smarts' used to be sure labels do not over-right each other is gone, and they axis labels can be impossible to read.

I really don't want the 'over-right smarts' to go away.

Is there a solution for this?

Re: Conditional Color Axis Label Color

Posted: Thu Dec 16, 2010 12:34 pm
by narcis
Hi Ed,

Sorry for the delayed reply. I'm afraid not. Colouring labels should be possible using standard labels. This is a bug(TV52015315) as Yeray posted here.

Re: Conditional Color Axis Label Color

Posted: Tue Dec 21, 2010 8:18 pm
by 10546565
[At least] One more question...

After I add labels to the bottom axis, if I reset the series but don't add customized labels, the axis do not appear at all.

See the attached demo--

1) When it is first started, black labels from 0... 19 show up.

2) Checking "Custom color captions" at the top and one red caption shows in place of the black ones.

3) Un-checking the check box results in no labels being shown for the bottom axis.

How can I get the standard labels to appear in #3?

Ed Dressel

Re: Conditional Color Axis Label Color

Posted: Wed Dec 22, 2010 10:16 am
by yeray
Hi Ed,
TestAlways wrote:How can I get the standard labels to appear in #3?
Setting the labels to be automatic when the checkbox isn't checked (add an "else" to your condition):

Code: Select all

Chart1.Axes.Bottom.Items.Automatic:=true;

Re: Conditional Color Axis Label Color

Posted: Wed Jan 05, 2011 3:09 pm
by yeray
Hi Ed,

I'd like to inform you that the bug with number [TV52015315] has been closed as described here