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:
FTitle.LabelFont.Orientation := 900; // default alignment is calLeft --> vertical title
- Find procedure TChartAxis.SetAlignment and replace the "case" block by
case FAlignment of
calBottom:
begin
FMarks.SetInsideDir(0, +1);
FTitle.LabelFont.Orientation := 0;
end;
calTop:
begin
FMarks.SetInsideDir(0, -1);
FTitle.LabelFont.Orientation := 0;
end;
calLeft:
begin
FMarks.SetInsideDir(+1, 0);
FTitle.LabelFont.Orientation := 900;
end;
calRight:
begin
FMarks.SetInsideDir(-1, 0);
FTitle.LabelFont.Orientation := -900;
end;
end;