Recent

Author Topic: [CLARIFIED]TChart: Wrong default value of .Title.LabelFont.Orientation  (Read 3994 times)

CM630

  • Hero Member
  • *****
  • Posts: 1674
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
This seems wrong, but maybe my expectations are not correct:

Sequence:
  Create a new TChart.
  Right click on “AxisList” in the Components palette and then click “Add Item”.
  A new Left aligned axis is created with index 2.
  Set captions to the titles of all axises and set .Visible = True for all of them.

Expected behaviour:
  The axises which are aligned to the left shall have their .Title.LabelFont.Orientation = 900.
  The axises which are aligned to the bottom shall have their .Title.LabelFont.Orientation = 0. 

Actual behaviour:
  .Title.LabelFont.Orientation = 900 for Axis 0 (as expected).
  .Title.LabelFont.Orientation = 0 for Axis 0 (NOT as expected). 
  The axises which are aligned to the bottom shall have their .Title.LabelFont.Orientation = 0 (as expected).
« Last Edit: March 17, 2026, 10:48:13 am by CM630 »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

paweld

  • Hero Member
  • *****
  • Posts: 1596
Re: TChart: Wrong default value of .Title.LabelFont.Orientation
« Reply #1 on: March 12, 2026, 01:34:53 pm »
You must set the title orientation to 90° for the new axes.
Tested on Lazarus trunk.
Best regards / Pozdrawiam
paweld

CM630

  • Hero Member
  • *****
  • Posts: 1674
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TChart: Wrong default value of .Title.LabelFont.Orientation
« Reply #2 on: March 12, 2026, 02:12:25 pm »
Yes, I am aware that if I set the orientation to 900 manually the title will be displayed fine.
But still there is a discrepancy - AxisList[0] is set to 900 by default, while AxisList[2] is set to 0 by default.
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 13484
Re: TChart: Wrong default value of .Title.LabelFont.Orientation
« Reply #3 on: March 12, 2026, 07:30:28 pm »
Committed in trunk/main a version in which the font of the axis title is rotated according to the axis Aligment (calBottom and calTop: 0°, calLeft: 90°, calRight: -90°).

I am not 100% happy with it because coupling these two properties overrides a change of Chart.Title.LabelFont.Orientation previously made by the user. But users adding new axes probably set the axis.Alignment first before they fine-tune the title orientation.

CM630

  • Hero Member
  • *****
  • Posts: 1674
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TChart: Wrong default value of .Title.LabelFont.Orientation
« Reply #4 on: March 12, 2026, 08:36:53 pm »
Committed in trunk/main a version in which the font of the axis title is rotated according to the axis Aligment (calBottom and calTop: 0°, calLeft: 90°, calRight: -90°).

I am not 100% happy with it because coupling these two properties overrides a change of Chart.Title.LabelFont.Orientation previously made by the user. But users adding new axes probably set the axis.Alignment first before they fine-tune the title orientation.
I read it a few times.
The issue is not about Chart.Title.LabelFont.Orientation, but about Chart1.AxisList.Axes[0].Title.LabelFont.Orientation. Is there some misunderstanding or these two properties are linked somehow?
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 13484
Re: TChart: Wrong default value of .Title.LabelFont.Orientation
« Reply #5 on: March 12, 2026, 10:14:38 pm »
Oh, sorry for the confusion. This was a typo. I meant "Axis.Title.LabelFont" instead of "Chart.Title.LabelFont".

CM630

  • Hero Member
  • *****
  • Posts: 1674
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TChart: Wrong default value of .Title.LabelFont.Orientation
« Reply #6 on: March 13, 2026, 07:53:45 am »
So how can one set the orientation previously?
The is no property “Axis.Title.LabelFont.”.
There are Chart1.LeftAxis.Title.LabelFont and Chart1.BottomAxis.Title.LabelFont, and also Chart1.AxisList[index].Title.LabelFont.
I found that the usage of LeftAxis and BottomAxis is dangerous and Chart1.AxisList[index].Title.LabelFont.Orientation seems to store nothing.
In the snippet below the title of Axis 2 is vertical, while the one of Axis 3 is horizontal (Lazarus 4.6), nothing seems to be stored (set previously).

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender:TObject);
  2. var
  3.   i: integer = 0;
  4. begin
  5.   for i:=0 to Chart1.AxisList.Count -1 do
  6.   begin
  7.     Chart1.AxisList[i].Title.Caption := 'Axis ' + IntToStr(i);
  8.     Chart1.AxisList[i].Title.Visible := True;
  9.   end;
  10.   Chart1.AxisList.Add;
  11.   Chart1.AxisList[Chart1.AxisList.Count -1].Title.Caption := 'Axis ' + IntToStr(Chart1.AxisList.Count -1);
  12.   Chart1.AxisList[Chart1.AxisList.Count -1].Title.Visible := True;
  13.   Chart1.AxisList[Chart1.AxisList.Count -1].Title.LabelFont.Orientation := 900;
  14.  
  15.   Chart1.AxisList.Add;
  16.   Chart1.AxisList[Chart1.AxisList.Count -1].Title.Caption := 'Axis ' + IntToStr(Chart1.AxisList.Count -1);
  17.   Chart1.AxisList[Chart1.AxisList.Count -1].Title.Visible := True;
  18. end;
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 13484
Re: TChart: Wrong default value of .Title.LabelFont.Orientation
« Reply #7 on: March 13, 2026, 11:03:21 am »
The is no property “Axis.Title.LabelFont.”.
Of course, "Axis" is a generic identifier here, I thought you'd understand this "sloppy" formulation. The correct name would be "Chart1.AxisList[index].Title.LabelFont".

I found that the usage of LeftAxis and BottomAxis is dangerous
What's wrong with them? Chart1.LeftAxis is the first axis in the AxisList which has Alignment=calLeft. The same, correspondingly, for BottomAxis.

In the snippet below the title of Axis 2 is vertical, while the one of Axis 3 is horizontal (Lazarus 4.6), nothing seems to be stored (set previously).
Now it's my turn to say "I don't understand": Why "stored"? You are creating the two axes at runtime, and therefore they will not be in the lfm file. I think the behavious is as expected in Laz 4.6 (and earlier): A new axis is created with Aligment=calLeft, and every title Font is created with Orientation 0. The only exception seems to be the default Chart.LeftAxis which has a vertical title because the Title.LabelFont.Orientation is changed explicitely after creating. In your sample, Axis 2 has a vertical title because you provide code to rotate it.

In the new version, the behaviour is changed: When the axis Alignment is changed the font is rotated if it is a vertical axis: in case of calLeft, the font.Orientation is 900, in case of calRight, it is -900 (its negative value is in accordance with Delphi). So, when a new axis is created it has Alignment=calLeft, and its title is vertical. When you want the new axis to be at the top, you'll have to set Alignment to calTop, and the title will rotate automatically to be horizontal. The only problem is that when you change the Title.Font.Orientation manually before you decide on the new axis Alignment - then the title orientation will jump to its new Alignment-dependent setting after you changed Axis.Alignment.

You can easily integrate the new code into your v4.6:
  • Make a backup copy of unit TAChartAxis; it is in folder components/tachart of your Lazarus installation.
  • Open this unit in the IDE
  • Find the constructor TChartAxis.Create. Add the following line at the end:
Code: Pascal  [Select][+][-]
  1.   FTitle.LabelFont.Orientation := 900;  // default alignment is calLeft --> vertical title
  • Find procedure TChartAxis.SetAlignment and replace the "case" block by
Code: Pascal  [Select][+][-]
  1.   case FAlignment of
  2.     calBottom:
  3.       begin
  4.         FMarks.SetInsideDir(0, +1);
  5.         FTitle.LabelFont.Orientation := 0;
  6.       end;
  7.     calTop:
  8.       begin
  9.         FMarks.SetInsideDir(0, -1);
  10.         FTitle.LabelFont.Orientation := 0;
  11.       end;
  12.     calLeft:
  13.       begin
  14.         FMarks.SetInsideDir(+1, 0);
  15.         FTitle.LabelFont.Orientation := 900;
  16.       end;
  17.     calRight:
  18.       begin
  19.         FMarks.SetInsideDir(-1, 0);
  20.         FTitle.LabelFont.Orientation := -900;
  21.       end;
  22.   end;
  • Rebuild the IDE
« Last Edit: March 13, 2026, 11:07:37 am by wp »

CM630

  • Hero Member
  • *****
  • Posts: 1674
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TChart: Wrong default value of .Title.LabelFont.Orientation
« Reply #8 on: March 13, 2026, 12:33:44 pm »
I found that the usage of LeftAxis and BottomAxis is dangerous
What's wrong with them? Chart1.LeftAxis is the first axis in the AxisList which has Alignment=calLeft. The same, correspondingly, for BottomAxis.

This code causes an exception when the button is pressed for the second time. I guess it is done on purpose.


Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs,StdCtrls,TAGraph, TAChartAxisUtils;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button2:TButton;
  16.     Chart1:TChart;
  17.     procedure Button2Click(Sender:TObject);
  18.     procedure FormCreate(Sender:TObject);
  19.   private
  20.     FSwapped : Boolean;
  21.   public
  22.  
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.  
  28. implementation
  29.  
  30. {$R *.lfm}
  31.  
  32. { TForm1 }
  33.  
  34. procedure TForm1.Button2Click(Sender:TObject);
  35. begin
  36.   FSwapped := not FSwapped;
  37.   if FSwapped
  38.     then Chart1.LeftAxis.Alignment := calRight
  39.     else Chart1.LeftAxis.Alignment := calLeft;
  40. end;
  41.  
  42. procedure TForm1.FormCreate(Sender:TObject);
  43. begin
  44.   FSwapped := False;
  45. end;
  46.  
  47. end.  

...
In the new version, the behaviour is changed: When the axis Alignment is changed the font is rotated if it is a vertical axis: in case of calLeft, the font.Orientation is 900, in case of calRight, it is -900 (its negative value is in accordance with Delphi). So, when a new axis is created it has Alignment=calLeft, and its title is vertical. When you want the new axis to be at the top, you'll have to set Alignment to calTop, and the title will rotate automatically to be horizontal. The only problem is that when you change the Title.Font.Orientation manually before you decide on the new axis Alignment - then the title orientation will jump to its new Alignment-dependent setting after you changed Axis.Alignment.
...
I get it now. Just like you, I am not sure that I like it.
I rather would expect that Chart1.AxisList.Add; would create a left aligned scale with LabelFont.Orientation := 900; and that no further changes of the alignment would influence the .Orientation.
« Last Edit: March 13, 2026, 12:36:50 pm by CM630 »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 13484
Re: TChart: Wrong default value of .Title.LabelFont.Orientation
« Reply #9 on: March 13, 2026, 02:03:58 pm »
This code causes an exception when the button is pressed for the second time. I guess it is done on purpose.
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.   if FSwapped
  3.     then Chart1.LeftAxis.Alignment := calRight
  4.  
I see. But this is clear: The "LeftAxis" is the first axis with Alignment = calLeft. When you change Left.Axis.Alignment to calRight, there is no more "LeftAxis", i.e. LeftAxis becomes nil.

I rather would expect that Chart1.AxisList.Add; would create a left aligned scale with LabelFont.Orientation := 900; and that no further changes of the alignment would influence the .Orientation.
But then you have the same problem when you want to create an additional horizontal axis: You add the axis which is calLeft by default with a vertical title, and when the behaviour is as you suggest, the title remains vertical after switchin Alignment to calTop or calBottom.

CM630

  • Hero Member
  • *****
  • Posts: 1674
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TChart: Wrong default value of .Title.LabelFont.Orientation
« Reply #10 on: March 14, 2026, 09:49:34 am »
I see. But this is clear: The "LeftAxis" is the first axis with Alignment = calLeft. When you change Left.Axis.Alignment to calRight, there is no more "LeftAxis", i.e. LeftAxis becomes nil.
I added some info about that in wiki.


I rather would expect that Chart1.AxisList.Add; would create a left aligned scale with LabelFont.Orientation := 900; and that no further changes of the alignment would influence the .Orientation.
But then you have the same problem when you want to create an additional horizontal axis: You add the axis which is calLeft by default with a vertical title, and when the behaviour is as you suggest, the title remains vertical after switchin Alignment to calTop or calBottom.
That sounds quite reasonable to me - when you change the alignment, you shall take care for the orientation.
Especially when changing the alignment of a vertical axis from Left to Right , you might want to change the .Orientation to 270 °, but you might prefer 90 °.
I am not trying to say that I am convinced which solution is better.
« Last Edit: March 14, 2026, 09:52:26 am by CM630 »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 13484
Re: TChart: Wrong default value of .Title.LabelFont.Orientation
« Reply #11 on: March 14, 2026, 11:30:54 am »
Especially when changing the alignment of a vertical axis from Left to Right , you might want to change the .Orientation to 270 °, but you might prefer 90 °.
Well, maybe it is more consistent if vertical axes always had a 90° title rather than rotating the right axis title to 270°. Changed this in the repository.

wp

  • Hero Member
  • *****
  • Posts: 13484
Re: TChart: Wrong default value of .Title.LabelFont.Orientation
« Reply #12 on: March 16, 2026, 06:22:26 pm »
Sorry, but I had to revert all the changes made here in relation to axis title orientation - too much trouble. See https://forum.lazarus.freepascal.org/index.php/topic,73650.msg578588.html#msg578588 (caused by incorrect default value of the font orientation in case of vertical axes). Moreover, changing the Chart1.LeftAxis.LabelFont.Orientation in Object Inspector gave not immediate feedback.

 

TinyPortal © 2005-2018