XE2, TeeChart Pro 2014.11 04.09
In the attached demo, the series caption and legend overlap. If it is vertically enlarged, the problem does not occur--but I don't want to waist vertical spacing.
Is there a way that fixes this that doesn't waist vertical spacing?
Ed Dressel
Series Caption and Legend Overlap
-
- Advanced
- Posts: 228
- Joined: Tue Aug 28, 2007 12:00 am
- Location: Oregon, USA
Series Caption and Legend Overlap
- Attachments
-
- Legend and Caption Overwrite.rar
- (1.84 KiB) Downloaded 1152 times
Re: Series Caption and Legend Overlap
Hello,
I've reproduced the problem so I've added it to the public tracker:
http://bugs.teechart.net/show_bug.cgi?id=947
In the meanwhile, you could use a TAnnotationTool instead of using the bottom axis title, and recalculate the margin on the bottom manually. Ie:
I've reproduced the problem so I've added it to the public tracker:
http://bugs.teechart.net/show_bug.cgi?id=947
In the meanwhile, you could use a TAnnotationTool instead of using the bottom axis title, and recalculate the margin on the bottom manually. Ie:
Code: Select all
uses Series, Math, TeeTools;
var bottomTitle: TAnnotationTool;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
Chart1.Align:=alClient;
Chart1.View3D:=false;
Chart1.Legend.Visible:=false;
with Chart1.AddSeries(TBarSeries) as TBarSeries do
begin
FillSampleValues();
Marks.Visible:=false;
for i:=0 to Count-1 do
Labels[i]:=FormatFloat('#0.##', YValue[i]) + #13 + 'Extra Line 1' + #13 + 'Extra Line 2';
end;
Chart1.Axes.Bottom.Title.Text:='Bottom Axis Title';
recalcBottomMargin;
end;
procedure TForm1.Chart1Resize(Sender: TObject);
begin
recalcBottomMargin;
end;
procedure TForm1.recalcBottomMargin;
function CountOccurences( const SubText: string;
const Text: string): Integer;
begin
Result := Pos(SubText, Text);
if Result > 0 then
Result := (Length(Text) - Length(StringReplace(Text, SubText, '', [rfReplaceAll]))) div Length(subtext);
end;
var i, maxHeight, nLines, tmpMargin: Integer;
begin
Chart1.Draw;
maxHeight:=0;
for i:=0 to Chart1[0].Count-1 do
begin
nLines:=CountOccurences(#13, Chart1[0].Labels[i]) + 1;
maxHeight:=Max(maxHeight, nLines*Chart1.Canvas.TextHeight(Chart1[0].Labels[i]));
end;
tmpMargin:=maxHeight;
if Chart1.Axes.Bottom.Title.Visible or Assigned(bottomTitle) then
begin
if not Assigned(bottomTitle) then
bottomTitle:=Chart1.Tools.Add(TAnnotationTool) as TAnnotationTool;
with bottomTitle do
begin
Text:=Chart1.Axes.Bottom.Title.Text;
Shape.Assign(Chart1.Axes.Bottom.Title);
Left:=Chart1.Axes.Bottom.IStartPos+(Chart1.Axes.Bottom.IAxisSize div 2) - (Chart1.Canvas.TextWidth(Text) div 2);
tmpMargin:=Chart1.Axes.Bottom.TickLength+maxHeight+Chart1.Canvas.TextHeight(Text);
Top:=Chart1.Axes.Bottom.PosAxis+tmpMargin;
Chart1.MarginBottom:=tmpMargin;
end;
Chart1.Axes.Bottom.Title.Visible:=false;
end;
Chart1.MarginUnits:=muPixels;
Chart1.MarginBottom:=tmpMargin;
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
-
- Advanced
- Posts: 228
- Joined: Tue Aug 28, 2007 12:00 am
- Location: Oregon, USA
Re: Series Caption and Legend Overlap
Thank you for your response.
I merged your code with my demo and the problem still occurs--the problem for me was legend overlap with captions. See the attached demo.
Is there a work around?
Ed Dressel
I merged your code with my demo and the problem still occurs--the problem for me was legend overlap with captions. See the attached demo.
Is there a work around?
Ed Dressel
- Attachments
-
- Legend and Caption Overwrite.rar
- (2.36 KiB) Downloaded 1196 times
Re: Series Caption and Legend Overlap
Hi Ed,
You can do something similar than what I was doing, setting the legend to be in the bottom though a custom position and adding the necessary margin to the bottom:
You can do something similar than what I was doing, setting the legend to be in the bottom though a custom position and adding the necessary margin to the bottom:
Code: Select all
constructor TForm1.Create(aOwner: TComponent);
var
I: Integer;
lValue: Double;
lCaption: string;
begin
inherited;
FAnnTool := nil;
lValue := 100;
for I := 1 to 5 do
begin
lValue := lValue * (1 + (Random * 0.2));
lCaption := inttostr(I);
if I = 3 then
lCaption := lCaption + #13 + 'Extra Caption Line';
Series1.AddBar(lValue, lCaption, clTeeColor);
end;
chrtSavingsNeeded.Axes.Bottom.Title.Text:='Bottom Axis Title';
RecalcBottomMargin;
end;
procedure TForm1.RecalcBottomMargin;
function CountOccurences( const aSubText, aText: string): Integer;
begin
Result := Pos(aSubText, aText);
if Result > 0 then
Result := (Length(aText) - Length(StringReplace(aText, aSubText, '', [rfReplaceAll]))) div Length(aSubtext);
end;
var i, maxHeight, nLines, tmpMargin, tmpHeight: Integer;
begin
chrtSavingsNeeded.Draw;
chrtSavingsNeeded.Canvas.Font.Assign(chrtSavingsNeeded.Axes.Bottom.Title.Font);
maxHeight:=0;
for i:=0 to chrtSavingsNeeded[0].Count-1 do
begin
nLines:=CountOccurences(#13, chrtSavingsNeeded[0].Labels[i]) + 1;
maxHeight:= Max(maxHeight, nLines*chrtSavingsNeeded.Canvas.TextHeight(chrtSavingsNeeded[0].Labels[i]));
end;
tmpMargin:=maxHeight+chrtSavingsNeeded.Axes.Bottom.TickLength;
if chrtSavingsNeeded.Axes.Bottom.Title.Visible or Assigned(FAnnTool) then
begin
if not Assigned(FAnnTool) then
FAnnTool:=chrtSavingsNeeded.Tools.Add(TAnnotationTool) as TAnnotationTool;
with FAnnTool do
begin
Text := chrtSavingsNeeded.Axes.Bottom.Title.Text;
Shape.Assign(chrtSavingsNeeded.Axes.Bottom.Title);
Left := chrtSavingsNeeded.Axes.Bottom.IStartPos+(chrtSavingsNeeded.Axes.Bottom.IAxisSize div 2) - (chrtSavingsNeeded.Canvas.TextWidth(Text) div 2);
Top := chrtSavingsNeeded.Axes.Bottom.PosAxis+tmpMargin;
tmpMargin := tmpMargin+chrtSavingsNeeded.Canvas.TextHeight(Text);
end;
chrtSavingsNeeded.Axes.Bottom.Title.Visible:=false;
end;
if chrtSavingsNeeded.Legend.Visible and (chrtSavingsNeeded.Legend.Alignment = laBottom) then
begin
chrtSavingsNeeded.Legend.CustomPosition:=true;
chrtSavingsNeeded.Legend.Left:=(chrtSavingsNeeded.Width div 2) - (chrtSavingsNeeded.Legend.Width div 2);
tmpHeight:=chrtSavingsNeeded.Legend.Height;
chrtSavingsNeeded.Legend.Top:=chrtSavingsNeeded.Axes.Bottom.PosAxis+tmpMargin;
tmpMargin:=tmpMargin+tmpHeight;
end;
chrtSavingsNeeded.MarginUnits:=muPixels;
chrtSavingsNeeded.MarginBottom:=tmpMargin;
end;
procedure TForm1.Resize;
begin
inherited;
RecalcBottomMargin;
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
-
- Advanced
- Posts: 228
- Joined: Tue Aug 28, 2007 12:00 am
- Location: Oregon, USA
Re: Series Caption and Legend Overlap
Thank you for your responses.
If I use the Footer.Text property for my charts sub-title, the overlap still occurs. (I tried to change the code you wrote but could not get it to work with my new demo).
Ed Dressel
If I use the Footer.Text property for my charts sub-title, the overlap still occurs. (I tried to change the code you wrote but could not get it to work with my new demo).
Ed Dressel
- Attachments
-
- Legend and Caption Overwrite.rar
- (2.63 KiB) Downloaded 1192 times
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Re: Series Caption and Legend Overlap
Hi Ed,
With the modifications David Berneda made to the code it's working fine now:
So you may expect this being fixed in the next maintenance release. If you are interested, you can also check David's new beta version here.
With the modifications David Berneda made to the code it's working fine now:
So you may expect this being fixed in the next maintenance release. If you are interested, you can also check David's new beta version 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 |
Instructions - How to post in this forum |
-
- Advanced
- Posts: 228
- Joined: Tue Aug 28, 2007 12:00 am
- Location: Oregon, USA
Re: Series Caption and Legend Overlap
It's difficult to release beta code to my end users--it doesn't go over very well when it doesn't work. How close is this to being a final release?
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Re: Series Caption and Legend Overlap
Hello Ed,
We expect this version being out in about one month.TestAlways wrote:How close is this to being a final release?
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |