Conditional Color Axis Label Color

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
TestAlways
Advanced
Posts: 228
Joined: Tue Aug 28, 2007 12:00 am
Location: Oregon, USA

Conditional Color Axis Label Color

Post by TestAlways » Thu Dec 09, 2010 4:22 pm

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

ChartIt
Newbie
Newbie
Posts: 29
Joined: Tue Mar 13, 2007 12:00 am

Re: Conditional Color Axis Label Color

Post by ChartIt » Fri Dec 10, 2010 3:56 am

Maybe this thread is relevant for you:
http://www.teechart.net/support/viewtop ... =3&t=11883

TestAlways
Advanced
Posts: 228
Joined: Tue Aug 28, 2007 12:00 am
Location: Oregon, USA

Re: Conditional Color Axis Label Color

Post by TestAlways » Fri Dec 10, 2010 7:07 pm

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

TestAlways
Advanced
Posts: 228
Joined: Tue Aug 28, 2007 12:00 am
Location: Oregon, USA

Re: Conditional Color Axis Label Color

Post by TestAlways » Fri Dec 10, 2010 8:23 pm

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?

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Conditional Color Axis Label Color

Post by Narcís » Thu Dec 16, 2010 12:34 pm

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

TestAlways
Advanced
Posts: 228
Joined: Tue Aug 28, 2007 12:00 am
Location: Oregon, USA

Re: Conditional Color Axis Label Color

Post by TestAlways » Tue Dec 21, 2010 8:18 pm

[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
Attachments
Axis Label Colors.zip
(3.14 KiB) Downloaded 697 times

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Conditional Color Axis Label Color

Post by Yeray » Wed Dec 22, 2010 10:16 am

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;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Conditional Color Axis Label Color

Post by Yeray » Wed Jan 05, 2011 3:09 pm

Hi Ed,

I'd like to inform you that the bug with number [TV52015315] has been closed as described here
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply