Legend Left or Right, Symbols.Squared, and Vert Spacing

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
JazzMan
Newbie
Newbie
Posts: 37
Joined: Fri Jun 18, 2004 4:00 am

Legend Left or Right, Symbols.Squared, and Vert Spacing

Post by JazzMan » Tue Aug 05, 2008 6:24 am

Folks,

If I have a Legend that is aligned Left or Right (rather than Top or Bottom), Symbols.Squared is set True, then all is fine. The symbols are squared.

Now.... if I set Vertical Spacing for the legends to a non-zero value, the symbols are no longer squared.

Can you reproduce this? I can demonstrate this using either Tee7New or Tee8New. What do you suggest I do to get Symbols.Squared to behave when the Vertical Spacing for Legend items is non-zero?

Thanks in advance,
richard diamond

Marc
Site Admin
Site Admin
Posts: 1261
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Post by Marc » Tue Aug 05, 2008 3:50 pm

Hello Richard,

There may be other ways of achieving this but the following use of the GetLegendRect event seems to work ok:

Code: Select all

procedure TForm1.Chart1GetLegendRect(Sender: TCustomChart;
  var Rect: TRect);
begin
  if (Chart1.Legend.VertSpacing <> 0) then
  Begin
    Chart1.Legend.Symbol.Squared:=False;
    Chart1.Legend.Symbol.WidthUnits:=lcsPixels;
    Chart1.Legend.Symbol.Width := Chart1.Legend.Item[0].SymbolRect.Bottom-Chart1.Legend.Item[0].SymbolRect.Top;
  end
  else
    Chart1.Legend.Symbol.Squared:=True;
end;
Regards,
Marc Meumann
Steema Support

JazzMan
Newbie
Newbie
Posts: 14
Joined: Fri Nov 15, 2002 12:00 am

Post by JazzMan » Tue Aug 05, 2008 4:45 pm

Marc,

Thanks so much. It's brilliant and straightforward.

I apologize for not mentioning this. I'm using V7. I'm guessing the Items property is in, and new with, V8?

While your solution will be of value to V8 owners, how would I V7'ize this?

Thanks!
richard diamond

JazzMan
Newbie
Newbie
Posts: 14
Joined: Fri Nov 15, 2002 12:00 am

Post by JazzMan » Tue Aug 05, 2008 6:28 pm

Marc,

In playing with your solution a bit more, here's what I came up with.

Code: Select all

procedure TForm1.Chart1BeforeDrawChart(Sender: TObject);
begin
  if( (  Chart1.Legend.VertSpacing <> 0 ) and
      (  Chart1.Legend.Symbol.Squared ) ) then begin
    Chart1.Legend.Symbol.Squared     := False;
    Chart1.Legend.Symbol.WidthUnits  := lcsPixels;
    Chart1.Legend.Symbol.Width         := -Chart1.Legend.Font.Height;
  end;
So as you can see the two differences are:
1) I had to put it in the BeforeDrawChart event. It seemed to have no effect (to my surprise), in Chart1GetLegendRect
2) Other than some minor tweaks (if Squared was FALSE, I wanted to leave it FALSE ), and to have it fit my situation, the other main change was to replace the line:

Code: Select all

  Chart1.Legend.Symbol.Width := Chart1.Legend.Item[0].SymbolRect.Bottom-Chart1.Legend.Item[0].SymbolRect.Top;
with

Code: Select all

    Chart1.Legend.Symbol.Width := -Chart1.Legend.Font.Height;
What it may lack in elegance it makes up for in the fact that it works for me..;) How would you clean my code up?

Regards,
richard diamond

Post Reply