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
Legend Left or Right, Symbols.Squared, and Vert Spacing
Hello Richard,
There may be other ways of achieving this but the following use of the GetLegendRect event seems to work ok:
Regards,
Marc Meumann
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;
Marc Meumann
Steema Support
Marc,
In playing with your solution a bit more, here's what I came up with.
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:
with
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
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;
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;
Code: Select all
Chart1.Legend.Symbol.Width := -Chart1.Legend.Font.Height;
Regards,
richard diamond