Caption goes outside of bounderies
Caption goes outside of bounderies
In a very simple demo (attached) I have a caption on the left axis (but this problem can occur on other axes as well) where the caption can go beyond the area it should if the app is made smaller--here is an image from the attached demo where I resized the app and the left axis caption goes outside of the area:
Is there a way to do word warp on the captions automatically? How can I make it so the caption always shows up?
Thank you,
Ed Dressel
Is there a way to do word warp on the captions automatically? How can I make it so the caption always shows up?
Thank you,
Ed Dressel
- Attachments
-
- Axis Caption.zip
- (1.67 KiB) Downloaded 1396 times
Ed Dressel
President
RetireReady Solutions
President
RetireReady Solutions
Re: Caption goes outside of bounderies
Hello,
You could check if the left axis title fits in the chart height and wrap the text accordingly. Ie:
You could check if the left axis title fits in the chart height and wrap the text accordingly. Ie:
Code: Select all
procedure TForm1.Chart1Resize(Sender: TObject);
var oneLineTitle: String;
titleHeight: Integer;
begin
oneLineTitle:=StringReplace(Chart1.Axes.Left.Title.Text, sLineBreak, '', [rfReplaceAll]);
Chart1.Canvas.AssignFont(Chart1.Axes.Left.Title.Font);
if Chart1.Height < Chart1.Canvas.TextWidth(oneLineTitle) then
Chart1.Axes.Left.Title.Text:=WrapText(oneLineTitle, sLineBreak, [' '], Chart1.Height div Chart1.Axes.Left.Title.Font.Size)
else
Chart1.Axes.Left.Title.Text:=oneLineTitle;
titleHeight:=Abs((Chart1.Axes.Left.Title.Text.CountChar(#13)+1)*Chart1.Axes.Left.Title.Font.Height);
Chart1.MarginLeft:=Round((titleHeight+5)*100/Chart1.Width);
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Caption goes outside of bounderies
Thank you for your response.
I have this problem in a dozen+ charts.
Could a future version have a .WrapText property? That would be easier.
I have this problem in a dozen+ charts.
Could a future version have a .WrapText property? That would be easier.
Ed Dressel
President
RetireReady Solutions
President
RetireReady Solutions
Re: Caption goes outside of bounderies
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Caption goes outside of bounderies
Your solution works well with the rendering of the TChart, but when creating an image, it does not work. See the attached demo, which has a TImage one third the height of the chart, but the caption does not size correctly.
How could this be done for rendering to an image?
Thank you,
Ed Dressel
How could this be done for rendering to an image?
Thank you,
Ed Dressel
- Attachments
-
- Axis Caption.zip
- (7.43 KiB) Downloaded 1412 times
Ed Dressel
President
RetireReady Solutions
President
RetireReady Solutions
Re: Caption goes outside of bounderies
Hello,
Sorry for the delay here.
You could create a new method (ie
Ie:
Sorry for the delay here.
You could create a new method (ie
WrapLeftAxisTitle
) and move the code from the OnResize
event to it. Then, you only have to add a few parameters to it and call it both at OnResize
event and in your AssignChartToGraphic
method.Ie:
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Caption goes outside of bounderies
We are a lot closer, but not quite there: if the legend is in the way (on the top or bottom) and has a large number of items in it, the caption can get truncated.
To reproduce this change the line in the constructor so that there are 20 sample values:
Thank you,
Ed Dressel
To reproduce this change the line in the constructor so that there are 20 sample values:
Code: Select all
Series1.FillSampleValues(20);
Ed Dressel
Ed Dressel
President
RetireReady Solutions
President
RetireReady Solutions
Re: Caption goes outside of bounderies
Hello,
You could wrap the text to fit the length you wish. In this case you may want to use
You could wrap the text to fit the length you wish. In this case you may want to use
ChartRect.Height
. Ie:
Code: Select all
procedure TForm1.WrapLeftAxisTitle(aChart: TChart; const aHeight: Integer);
var
lOneLineTitle: String;
lTitleHeight: Integer;
lTitle: TChartAxisTitle;
lHeight: Integer;
begin
Assert(aChart <> nil);
aChart.Draw;
lTitle := aChart.Axes.Left.Title;
lOneLineTitle := StringReplace(lTitle.Text, sLineBreak, ' ', [rfReplaceAll]);
lOneLineTitle := StringReplace(lOneLineTitle, ' ', ' ', [rfReplaceAll]);
aChart.Canvas.AssignFont(lTitle.Font);
lHeight:=aHeight;
if (aChart.Legend.Alignment=laTop) or (aChart.Legend.Alignment=laBottom) then
lHeight:=aChart.ChartRect.Height*aHeight div aChart.Height;
if lHeight < aChart.Canvas.TextWidth(lOneLineTitle) then
lTitle.Text := WrapText(lOneLineTitle, sLineBreak, [' '], lHeight div lTitle.Font.Size)
else
lTitle.Text := lOneLineTitle;
lTitleHeight:=Abs( (lTitle.Text.CountChar(#13) + 1) * lTitle.Font.Height);
aChart.MarginLeft := Round((lTitleHeight + 5) * 100 / aChart.Width);
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Caption goes outside of bounderies
Perfect. Thank you for the quick response.
Ed Dressel
President
RetireReady Solutions
President
RetireReady Solutions