Show/Hide individual Axis Custom Labels

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Piero
Newbie
Newbie
Posts: 2
Joined: Tue Dec 28, 2010 12:00 am

Show/Hide individual Axis Custom Labels

Post by Piero » Wed Oct 12, 2011 11:39 am

Hello, I'm having this type of problem with axis custom labels:
I have a TChart in which I dynamically create a set of TBarSeries, each one having a single bar value. I want to display in the bottom axis a string of text under each bar. I do this by adding custom labels to the chart BottomAxis:

Code: Select all

      for i:=0 to NSeries-1 do
         begin
            Series:=TBarSeries.Create(Chart);
            Series.AddXY(i,Values[i,0]);
            Chart.BottomAxis.Items.Add(i,SeriesTitles[i]);
            Series.ParentChart:=Chart;
       end;
This works. But then, I want to show/hide the above custom labels depending on which series are made visible by the user. I try do it in this way:

Code: Select all

   
with Chart do
      for i:=0 to SeriesCount-1 do     
         if (Pos('1',Series[i].Title) <> 0) then   // criteria that I'm using to decide wheter a series should be shown or not
            begin
               Series[i].Active:=true;
               BottomAxis.Items[i].Format.Visible:=true;
            end
         else
            begin
               Series[i].Active:=false;
               BottomAxis.Items[i].Format.Visible:=false;
            end;
Chart.Refresh;
but this doesn't work, because all custom labels previously defined are always displayed, independently if the corresponding Series is active or not.
I think there should be some other BottomAxis property to be set to get the desired result, but I cannot find which one niether from help nor from examples.
Thank you very much for your help.
Piero

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

Re: Show/Hide individual Axis Custom Labels

Post by Yeray » Fri Oct 14, 2011 8:15 am

Hello Piero,

It seems that the Items.Format.Visible property isn't hiding the custom labels. I've added it to the wish list to be investigated for future releases (TV52015785).
In the meanwhile I'm afraid the only solution I can think is drawing the labels manually in the OnAfterDraw event, and control there if a label should be drawn or not.

Code: Select all

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var i: Integer;
begin
  for i:=0 to Chart1.SeriesCount-1 do
    if Chart1[i].Active then //add your condition here
      Chart1.Canvas.TextOut(Chart1[i].CalcXPos(0), Chart1.Axes.Bottom.PosAxis+5, SeriesTitles[i]);
end;
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

Piero
Newbie
Newbie
Posts: 2
Joined: Tue Dec 28, 2010 12:00 am

Re: Show/Hide individual Axis Custom Labels

Post by Piero » Fri Oct 14, 2011 2:13 pm

Hello Yeray,
your workaround is fine, I implemented it in my software and it does exactly what I desired!
Thank you very much for your help.

Piero

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

Re: Show/Hide individual Axis Custom Labels

Post by Yeray » Mon Oct 17, 2011 9:14 am

Hello Piero,

I'm glad to hear that! :)
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