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

Message ListMessage List     Post MessagePost Message

  setting alignment on the plot chart
Posted by Ji-hyeon Choi on Jan-31-2024 14:11
When setting alignment on the plot chart, if you set it to top, it is set to bottom. How do I set it up?

TextBox *pLabel = pyramidChart.setCenterLabel(TCHARtoUTF8(m_previewChartLayout.m_label.data()), TCHARtoUTF8(m_previewChartLayout.m_labelFont.m_fontName.data()),
            m_previewChartLayout.m_labelFont.m_fontSize,
            m_previewChartLayout.m_labelFontColor.GetChartColor(&pyramidChart));

         // set background
         pLabel->setBackground(m_previewChartLayout.m_labelBackColor.GetChartColor(&pyramidChart),
            m_previewChartLayout.m_labelEdgeColor.GetChartColor(&pyramidChart),
            m_previewChartLayout.m_labelRaisedEffect.GetRaisedEffect());

         //mkshin 2012/02/27 Label Alignment 추가
         pLabel->setAlignment(m_previewChartLayout.m_labelAlignment);
         pLabel->setPos((int)m_previewChartLayout.m_positionX, (int)m_previewChartLayout.m_positionY); //mkshin 2012/08/01 LabelPosition 추가

         // set font angle
         pLabel->setFontAngle(m_previewChartLayout.m_labelAngle, m_previewChartLayout.m_labelAngleVertical);

  Re: setting alignment on the plot chart
Posted by Peter Kwan on Feb-01-2024 01:12
Attachments:
Hi Ji-hyeon Choi,

For your case, the TextBox is created with setCenterLabel, so the TextBox will be at the center of the pyramid segment.

The TextBox::setAlignment refers to the alignment of text within the TextBox. I have attached an image to show top alignment. You can see the text is top-aligned within the text box. Note that top-alignment means the text is under the top edge of the TextBox, not above the top edge.

I have attached an explanation of what would happen if you reduce the TextBox size to 1 x 1 pixel. In this case, the text will overflow outside the TextBox, but it is still under the top edge of the TextBox. As the TextBox at the center of the pyramid segment, the text will be under the middle point of the pyramid segment.

If you want to the text to be above the middle point, please use bottom alignment.

If you want to set the TextBox to 1 x 1 pixel to control alignment, and you also want to have a TextBox surrounding the text to provide a background color, you can use CDML to add a box to the text. An example is like:

TextBox *p = c->setCenterLabel("<*block,bgcolor=DDDDDD,margin=2*>{label}n{percent}%", "Arial Bold");

For CDML, see:

https://www.advsofteng.com/doc/cdcpp.htm#cdml.htm

Best Regards
Peter Kwan
top_alignment.png
alignment_explanation.png

  Re: setting alignment on the plot chart
Posted by ji-hyeon choi on Feb-01-2024 09:03
Hi Peter Kwan

Thank you for your response. But there is something I don't understand. Assuming you mentioned that the text box is 1x1 pixels, we don't set the size of the text box.


Show my upload image file.

  Re: setting alignment on the plot chart
Posted by Peter Kwan on Feb-02-2024 03:19
Attachments:
Hi ji-hyeon choi,


You mentioned "Show my upload image file". However, I cannot see any uploaded image  in your message. To update a file, use "Choose File" to select the file, then use "Send File" to upload the file. The file must be less than 250K bytes, otherwise it cannot be uploaded. Alternatively, you can send your support request to me by email (pkwan@advsofteng.net).

The following is a complete example modified from the Simple Pyramid Chart sample code. I use bottom alignment to put the text above the center line of the pyramid segment.


    // The data for the pyramid chart
    double data[] = {156, 123, 211, 179};
    const int data_size = (int)(sizeof(data)/sizeof(*data));

    // The labels for the pyramid chart
    const char* labels[] = {"Funds", "Bonds", "Stocks", "Cash"};
    const int labels_size = (int)(sizeof(labels)/sizeof(*labels));

    // Create a PyramidChart object of size 360 x 360 pixels
    PyramidChart* c = new PyramidChart(360, 360);

    // Set the pyramid center at (180, 180), and width x height to 150 x 180 pixels
    c->setPyramidSize(180, 180, 150, 300);

    // Set the pyramid data and labels
    c->setData(DoubleArray(data, data_size), StringArray(labels, labels_size));

    // Add labels at the center of the pyramid layers using Arial Bold font. The labels will have
    // two lines showing the layer name and percentage.
    TextBox *p = c->setCenterLabel("<*block, bgcolor=BBDDFF, margin=2*>{label}n{percent}%", "Arial Bold");
    p->setSize(1, 1);
    p->setAlignment(Chart::Bottom);

    // Output the chart
    viewer->setChart(c);


Best Regards
Peter Kwan
bottom_alignment.png

  Re: setting alignment on the plot chart
Posted by Ji-hyeon Choi on Feb-02-2024 10:03
oh i'm sorry. please show upload image