ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Adding angled text relative text baseline
Posted by David Wilson on Jan-11-2011 03:20
To start, I want to note that I have generally found ChartDirector to a very useful charting package.

I have a question in relation to an application I am working on. I need to place text labels on lines in a line chart. The labels need to sit just above the lines and approximately parallel to the lines.

The only method I have found for placing text on a line chart is BaseChart::addText(x, y, ...), where (x, y) is the upper left corner of a TextBox bounding the text. In my application, it would be more useful to place the text relative its center baseline. Are there any text placement methods or functions for placing text relative the text features?

Thank you for your help.

  Re: Adding angled text relative text baseline
Posted by Peter Kwan on Jan-12-2011 02:33
Hi David,

Unluckily, in ChartDirector, there is no method to obtain the position of the "baseline" of a text (by "center baseline", I assume you refer to the baseline position in topography).

However, you can easily obtain the bounding box of the text (by using Box.getWidth and Box.getHeight to get the width and height of the text box), so you can put the text box so that its bottom edge is aligned with a given horizontal line. For example, you may add a text box, obtained its height, and then adjust its position (using Box.setPos).

Also, there is an "alignment" parameter in addText. The documentation says it aligns the text within the text box. However, if you do not specify the text box size (using Box.setSize), there is no container box to align the text to. In this case, ChartDirector will assume the box size is 0. If you use BottomLeft as the alignment, the bottom edge of the text will align with the bottom edge of the box. As the box is zero in height, the bottom edge of the box is at the given y-coordinate used in addText. That means the text will be bottom aligned to the given y-coordinate.

Hope this can help.

Regards
Peter Kwan