Hello,
I have found that if you make the chart label too big, the label can overwrite the title.
I have fixed the problem in chart.pas so that it works in my application. But it only takes into account the left axis, which is the only one I currently use. Look for "dn code added here"
procedure TChartTitle.DrawTitle;
var tmpXPosTitle : Integer;
tmpMargin : Integer;
FontH : Integer;
tmpFrameWidth : Integer;
Procedure DrawTitleLine(AIndex:Integer);
Var St : String;
APos : Integer;
Begin { draw a title text line }
St:=Text[AIndex];
APos:=AIndex*FontH+tmpFrameWidth;
if IOnTop then Inc(APos,ShapeBounds.Top)
else APos:=ShapeBounds.Bottom-FontH-APos;
if Alignment=taRightJustify then
tmpXPosTitle:=ShapeBounds.Right-ParentChart.Canvas.TextWidth(St)-(tmpMargin div 2)
else
if Alignment=taCenter then
tmpXPosTitle:=((ShapeBounds.Left+ShapeBounds.Right) div 2)-(ParentChart.Canvas.TextWidth(St) div 2);
ParentChart.Canvas.TextOut(tmpXPosTitle,APos,St);
end;
Var t : Integer;
tmpMaxWidth : Integer;
tmp : Integer;
tmpFrameVisible : Boolean;
lblHeight: Integer;
{$IFDEF CLR}
tmpR : TRect;
{$ENDIF}
Begin
if Visible and (Text.Count>0) then
begin
{ calculate title shape margin }
tmpFrameVisible:=Frame.Visible and (Frame.Color<>clTeeColor);
if tmpFrameVisible then tmpFrameWidth:=Frame.Width
else tmpFrameWidth:=0;
if Bevel<>bvNone then tmpFrameWidth:=BevelWidth;
{ apply title margins }
if not FCustomPosition then
begin
ShapeBounds:=ParentChart.ChartRect;
if IOnTop then ShapeBounds.Top:=ShapeBounds.Top+tmpFrameWidth;
end;
{ prepare title font }
With ParentChart.Canvas do
begin
AssignFont(Self.Font);
TextAlign:=TA_LEFT;
FontH:=FontHeight;
end;
{ autosize title height on number of text lines }
if IOnTop or FCustomPosition then
ShapeBounds.Bottom:=ShapeBounds.Top+Text.Count*FontH
else
ShapeBounds.Top :=ShapeBounds.Bottom-Text.Count*FontH;
{ apply margins to bottom and right sides }
if not FCustomPosition then
InflateRect(ShapeBounds,tmpFrameWidth,tmpFrameWidth);
tmpMargin:=ParentChart.Canvas.TextWidth('W');
{ resize Title to maximum Chart width }
if AdjustFrame then
begin
tmpMaxWidth:=0;
for t:=0 to Text.Count-1 do
Begin
tmp:=ParentChart.Canvas.TextWidth(Text[t]);
if tmp>tmpMaxWidth then tmpMaxWidth:=tmp;
end;
Inc(tmpMaxWidth,tmpMargin+tmpFrameWidth);
With ShapeBounds do
Case Alignment of
taLeftJustify : Right:=Left +tmpMaxWidth;
taRightJustify : Left :=Right-tmpMaxWidth;
taCenter : begin
if FCustomPosition then Right:=Left+tmpMaxWidth;
tmp:=(Left+Right) div 2;
Left :=tmp-(tmpMaxWidth div 2);
Right:=tmp+(tmpMaxWidth div 2);
end;
end;
end;
{ draw title shape }
Draw;
if Alignment=taLeftJustify then tmpXPosTitle:=ShapeBounds.Left+(tmpMargin div 2);
{ draw all Title text lines }
ParentChart.Canvas.BackMode:=cbmTransparent;
for t:=0 to Text.Count-1 do DrawTitleLine(t);
{ calculate Chart positions after drawing the titles / footers }
if not FCustomPosition then
begin
tmp:=TeeTitleFootDistance+tmpFrameWidth;
if not Transparent then
Inc(tmp,Shadow.VertSize);
// dn code added here
parentChart.canvas.assignFont((parentChart as TChart).leftAxis.LabelsFont);
lblHeight:=ParentChart.canvas.fontHeight;
if (lblHeight div 2) > tmp then
tmp:=(lblHeight div 2)+TeeTitleFootDistance;
// end of dn added code
{$IFDEF CLR}
tmpR:=ParentChart.ChartRect;
if IOnTop then
tmpR.Top:=ShapeBounds.Bottom+tmp
else
tmpR.Bottom:=ShapeBounds.Bottom-tmp-Text.Count*FontH;
ParentChart.ChartRect:=tmpR;
{$ELSE}
if IOnTop then
ParentChart.ChartRect.Top:=ShapeBounds.Bottom+tmp
else
ParentChart.ChartRect.Bottom:=ShapeBounds.Bottom-tmp-Text.Count*FontH;
{$ENDIF}
ParentChart.RecalcWidthHeight;
end;
end;
end;
label overwrites titles
-
- Newbie
- Posts: 71
- Joined: Fri Jul 02, 2004 4:00 am
- Location: Culver City
- Contact:
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi David,
Thanks for advising and your suggested solution.
However, this solution can not be used for a general case as it doesn't distinguish among Title(s) and Footer(s), if the axis labels have an angle different from zero or if its text is aligned to the right or to the left. It also doesn't consider the righ axis.
You should put your code into your program as it is very specific. The ideal place for the code to be is where the "AxisRect" is calculated so that it considers that the font size can be greater than the axis bounds.
I've added this defect to our bug list to be fixed for future releases. But there's not an easy solution to it .
Thanks for advising and your suggested solution.
However, this solution can not be used for a general case as it doesn't distinguish among Title(s) and Footer(s), if the axis labels have an angle different from zero or if its text is aligned to the right or to the left. It also doesn't consider the righ axis.
You should put your code into your program as it is very specific. The ideal place for the code to be is where the "AxisRect" is calculated so that it considers that the font size can be greater than the axis bounds.
I've added this defect to our bug list to be fixed for future releases. But there's not an easy solution to it .
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 |