2

I use fixed LabelsSize and TitleSize to keep my TChart LeftAxis at the same position, but the axis title (90° vertical) move around depending on its length. It is clear that the title's X position is calculated from the centre of the 0° (horizontal) string length instead of at a fixed position for the top or bottom of the 90° text, which is independent of length.

Is there a way around this?

Padding with spaces does not work, presumably because these are stripped before the title is plotted.

Thanks

Johan
  • 74,508
  • 24
  • 191
  • 319
  • Which RAD Studio/C++ Builder and TeeChart versions are you using? There have been some related improvements with most recent versions, for example: http://bugs.teechart.net/show_bug.cgi?id=1185. If you provide a test case we can run it with our sources to check whether your problem is fixed or not. – Narcís Calvet Aug 26 '15 at 08:21
  • Do you have a sample project we can test here to check whether the problem is fixed or not? – Narcís Calvet Aug 27 '15 at 13:57
  • Sorry Narcis, I forgot to add that I use TeeChart that comes with C++Buider XE5. The problem is easily checked in design mode by setting the left axis title of any XY plot to 90° and see how it moves around with changes in title length. Change orientation to 0° and see how the movement (properly) follows the title length, as one would want with a horizontal title. The point of a vertical title is obviously that it does not move around with title length. I set LabelsSize to a large enough constant so that label lengths (horizontal labels) would not push title left. – user2618654 Aug 27 '15 at 14:05
  • Thanks for the info. I think this is fixed with the latest maintenance release. You can download a fully functional evaluation version at http://www.steema.com/download/vcl. Embarcadero's free update (http://cc.embarcadero.com/item/29708) won't fix it, I'm afraid. – Narcís Calvet Aug 27 '15 at 14:09
  • Thank you very much for the response! – user2618654 Aug 27 '15 at 14:14

1 Answers1

1

A solution/workaround to this bug (without ditching the bundled version in favor of the evaluation version) is to set the AutoSize property of the title to false, and then set the Width and Height of the title manually to the height of the text to be displayed.

I am using Delphi XE5, and my code looks like this:

lBitMap := TBitMap.Create;
try
  lBitMap.Canvas.Font := Chart1.LeftAxis.Title.Font;
  Chart1.LeftAxis.Title.Width := lBitMap.Canvas.TextHeight(Chart1.LeftAxis.Title.Caption)+5;
  Chart1.LeftAxis.Title.Height := lBitMap.Canvas.TextHeight(Chart1.LeftAxis.Title.Caption)+5;
  Chart1.LeftAxis.Title.AutoSize := false;
  Chart1.LeftAxis.Title.TextAlignment := taCenter;
finally
  lBitMap.Free;
end;

Something analog can probably be done in C++, especially since most of the VCL is the same between Delphi and C++ builder.

EDIT 1: Added TextAlignment which should be set to taCenter so that the title is centered to the axis
EDIT 2: Used font of the title to get TextHeight - useful if you change the default font

vehystrix
  • 418
  • 5
  • 9