axis title overlap
-
- Newbie
- Posts: 71
- Joined: Fri Jul 02, 2004 4:00 am
- Location: Culver City
- Contact:
axis title overlap
hello.
I have my axis title size set to zero, so the axis titles should not overlap the labels. However, this still happens sometimes. Is this because I set custom label text on the onGetAxisLabel event? If so, is there any way to activate automatic spacing in this case?
I have my axis title size set to zero, so the axis titles should not overlap the labels. However, this still happens sometimes. Is this because I set custom label text on the onGetAxisLabel event? If so, is there any way to activate automatic spacing in this case?
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hello David,
Could you please post an example we can run "as-is" to reproduce the problem here and help you finding a solution for it? You can post your files at [url]news://www.steema.net/steema.public.attachments[/url] newsgroup.
Thanks in advance.
Could you please post an example we can run "as-is" to reproduce the problem here and help you finding a solution for it? You can post your files at [url]news://www.steema.net/steema.public.attachments[/url] newsgroup.
Thanks in advance.
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 |
-
- 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 Dave,
Thanks for the example application. It has an easy solution which is customizing labels size. Using the code below on your project works fine.
Thanks for the example application. It has an easy solution which is customizing labels size. Using the code below on your project works fine.
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
var
cntr: Integer;
begin
for cntr:=0 to 20 do
series1.addXY(cntr*1000,cntr*50);
Chart1.Axes.Left.LabelsSize:=50;
end;
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 |
-
- Newbie
- Posts: 71
- Joined: Fri Jul 02, 2004 4:00 am
- Location: Culver City
- Contact:
Hello Narcis,
Thank you for your prompt reply. I found the labelSize property myself of course. The question is, how do I know WHAT to make the label size. In my application, I have no idea what the data is going to be and what the axis labels are going to be displayed (its quite a complicated algorithm in the onGetAxisLabel event).
so, somehow I need to get all of the axis labels and then figure out what the longest one will be, then make the labelSize an appropriate value. This is what I assume you do normally, when labelSize is 0, but you don't do it when I supply custom labels.
In an idea world, you would gather up all the custom labels that I am sending to you, and then if the labelSize is 0, do what you normally do, which is automatically figure out the size.
So my question is:
1. How do I plug in to TChart to figure out what the longest label is?
2. Once I know what the longest label is, how do I convert that to an appropriate .LabelSize value?
Thank you for your help.
Thank you for your prompt reply. I found the labelSize property myself of course. The question is, how do I know WHAT to make the label size. In my application, I have no idea what the data is going to be and what the axis labels are going to be displayed (its quite a complicated algorithm in the onGetAxisLabel event).
so, somehow I need to get all of the axis labels and then figure out what the longest one will be, then make the labelSize an appropriate value. This is what I assume you do normally, when labelSize is 0, but you don't do it when I supply custom labels.
In an idea world, you would gather up all the custom labels that I am sending to you, and then if the labelSize is 0, do what you normally do, which is automatically figure out the size.
So my question is:
1. How do I plug in to TChart to figure out what the longest label is?
2. Once I know what the longest label is, how do I convert that to an appropriate .LabelSize value?
Thank you for your help.
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Dave,
Using the code below works fine for me.
Using the code below works fine for me.
Code: Select all
procedure TForm1.Chart1GetAxisLabel(Sender: TChartAxis;
Series: TChartSeries; ValueIndex: Integer; var LabelText: String);
begin
if ((Sender=Chart1.Axes.Left) and
(Chart1.Axes.Left.LabelsSize < Length(LabelText)*5)) then
Chart1.Axes.Left.LabelsSize:=Length(LabelText)*5;
end;
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 |
-
- Newbie
- Posts: 71
- Joined: Fri Jul 02, 2004 4:00 am
- Location: Culver City
- Contact:
Hi Narcis,
Ok, I see the theory. However, how would I account for different font sizes (my users scan switch label font size). Obviously, multiplying by 5 is not going to work in all cases.
Is the labelSize equal to pixels, i.e. if I measure that canvas.textextent of the labelText then use that, will I be okay?
Ok, I see the theory. However, how would I account for different font sizes (my users scan switch label font size). Obviously, multiplying by 5 is not going to work in all cases.
Is the labelSize equal to pixels, i.e. if I measure that canvas.textextent of the labelText then use that, will I be okay?
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Dave,
Yes, LabelsSize is in pixels. To have a more accurate formula, considering font size, you can add font size as a variable:
Yes, LabelsSize is in pixels. To have a more accurate formula, considering font size, you can add font size as a variable:
Code: Select all
Chart1.Axes.Left.LabelsFont.Size
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 |
-
- Newbie
- Posts: 71
- Joined: Fri Jul 02, 2004 4:00 am
- Location: Culver City
- Contact:
-
- Newbie
- Posts: 71
- Joined: Fri Jul 02, 2004 4:00 am
- Location: Culver City
- Contact:
Hello Narcis,
As I implement this more, I realize this solution does not work. During the course of the drawing, as I keep changing the labelSize based upon the "latest" custom axis label, the chart repaints and flickers. It seems to paint once with the original labelSize and then again with the updated one.
Tracing through your code, I seem to have found something strange. When calculating the automatic label size, you have the following function
Function MaxLabelsValueWidth:Integer;
var tmp : Double;
tmpA : Double;
tmpB : Double;
OldGetAxisLabel : TAxisOnGetLabel;
tmpNum : Integer;
begin
if (IsDateTime and FExactDateTime) or RoundFirstLabel then
begin
tmp:=CalcIncrement;
tmpA:=tmp*Int(IMinimum/tmp);
tmpB:=tmp*Int(IMaximum/tmp);
end
else
begin
tmpA:=IMinimum;
tmpB:=IMaximum;
end;
With ParentChart do
begin
OldGetAxisLabel:=FOnGetAxisLabel;
FOnGetAxisLabel:=nil;
With Canvas do
result:=TextWidth(' ')+
Math.Max(MultiLineTextWidth(LabelValue(tmpA),tmpNum),
MultiLineTextWidth(LabelValue(tmpB),tmpNum));
FOnGetAxisLabel:=OldGetAxisLabel;
end;
end;
For some reason, you set the FonGetAxisLabel to nil. Thus, the LabelValue method returns the incorrect value in my case, because I do have an onGetAxisLabel method. The labelValue method returns just the default axis label, which is totally incorrect, because you have set the FOnGetAxisLabel to nil.
Adjusting the axis labels as you are drawing causes a flicker, which makes sense since the labelSize is being updated as drawing continues. it seems that you have the infrastructure for the correct behavious, i.e. if the labelSize is zero you get the maximum label size and use that. However, disconnecting the onGetAxisLabel is making that not work in my case. Is there a reason why you are doing this? Is there any danger in not setting the OnGetAxisLabel to nil?
As I implement this more, I realize this solution does not work. During the course of the drawing, as I keep changing the labelSize based upon the "latest" custom axis label, the chart repaints and flickers. It seems to paint once with the original labelSize and then again with the updated one.
Tracing through your code, I seem to have found something strange. When calculating the automatic label size, you have the following function
Function MaxLabelsValueWidth:Integer;
var tmp : Double;
tmpA : Double;
tmpB : Double;
OldGetAxisLabel : TAxisOnGetLabel;
tmpNum : Integer;
begin
if (IsDateTime and FExactDateTime) or RoundFirstLabel then
begin
tmp:=CalcIncrement;
tmpA:=tmp*Int(IMinimum/tmp);
tmpB:=tmp*Int(IMaximum/tmp);
end
else
begin
tmpA:=IMinimum;
tmpB:=IMaximum;
end;
With ParentChart do
begin
OldGetAxisLabel:=FOnGetAxisLabel;
FOnGetAxisLabel:=nil;
With Canvas do
result:=TextWidth(' ')+
Math.Max(MultiLineTextWidth(LabelValue(tmpA),tmpNum),
MultiLineTextWidth(LabelValue(tmpB),tmpNum));
FOnGetAxisLabel:=OldGetAxisLabel;
end;
end;
For some reason, you set the FonGetAxisLabel to nil. Thus, the LabelValue method returns the incorrect value in my case, because I do have an onGetAxisLabel method. The labelValue method returns just the default axis label, which is totally incorrect, because you have set the FOnGetAxisLabel to nil.
Adjusting the axis labels as you are drawing causes a flicker, which makes sense since the labelSize is being updated as drawing continues. it seems that you have the infrastructure for the correct behavious, i.e. if the labelSize is zero you get the maximum label size and use that. However, disconnecting the onGetAxisLabel is making that not work in my case. Is there a reason why you are doing this? Is there any danger in not setting the OnGetAxisLabel to nil?