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

Message ListMessage List     Post MessagePost Message

  Label Alignment not working
Posted by Ankit Jain on Dec-07-2017 00:09
Attachments:
Hi Peter,
I was trying to align(Left/right/center) value label of my bar chart .But they remains at the center of the bar.
Please find below code snippet i am using

for (int i = 0; i < pLayer.getDataPointCount(); i++)
{
if (pLayer.getShowValueLabels() == eShowAllLabels)
{
tb = pBarLayer.addCustomAggregateLabel((int)pLayer.getDataPoint(i).getXPosition(), pLayer.getDataPoint(i).getValueLabel(),
pFont.getFileName(), pFont.getPointSize(), pFont.getColor());
//tb.setMargin(0);
leftX = tb.getLeftX();
topY = tb.getTopY();

tb.setAlignment(6);
tb.setFontAngle(-pLayer.getValueLabelRotation());
tb.setPos(leftX , topY - pLayer.getValueLabelPlacement());

}
              }

I have given alignment as right but its not working.I don't know whats happening.

Thanks
Ankit
testImage.png

  Re: Label Alignment not working
Posted by Peter Kwan on Dec-08-2017 03:51
Hi Ankit,

ChartDirector internally is using setAlignment to position the aggregate label at the center of the bar. If your code sets the alignment, it will be overwritten by ChartDirector internally, so the alignment set by your code has no effect.

Another issue is that for most of the cases, the "alignment" in ChartDirector is similar to the alignment used in word processors (eg. Microsoft Word). The text is supposed to be inside a container, which is a "page" in a word processor. Left alignment means the left side of the text is positioned on the left side of the page.

For the labels, it is a "TextBox" object, and so there is actually a box containing the text. By default, the box is transparent, so you cannot see it. If your code does not set the box size, the box will be set to the size of the text. If the text contain only one line, the alignment will have no effect, as the text is is already aligned with the box on all four sides. If your text has multiple lines of different, you can see the lines can be alignment to the left or right or center.

For your case, I assume by "left" alignment, it means the left side or the text is alignment with the left side of the bar. (There are many interpretations of "left" alignment. Some people may think it means the text is on the left of the bar, which means the left side of the text is aligned with the right side of the bar.)

If you can estimate the width of the bar in pixels (which should be easy as your code seems to control the bar gap), the alignment can be achieved with CDML. It is like:

<*block,halign=left,width=xxx*>My Label<*/*>

In the above, xxx is the bar width. Basically, the above creates another "block" within the TextBox, where the block width is the same as the bar width. The text is within the block, so left alignment means the left side of the text is aligned with the left side of the block, which must be the same as the left side of the bar (assuming the box and the bar is of the same width).

For testing, it is often useful to make the "box" non-transparent, so you can see it actual size and position. This can be done using:

tb.setBackground(0x7fcccccc);

Hope this can help.

Regards
Peter Kwan

  Re: Label Alignment not working
Posted by Ankit Jain on Dec-11-2017 19:11
Thanks Peter .Appreciate your quick replies.