Page 1 of 1
Legend Left or Right, Symbols.Squared, and Vert Spacing
Posted: Tue Aug 05, 2008 6:24 am
by 9337917
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
Posted: Tue Aug 05, 2008 3:50 pm
by Marc
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
Posted: Tue Aug 05, 2008 4:45 pm
by 5887342
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
Posted: Tue Aug 05, 2008 6:28 pm
by 5887342
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