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

Message ListMessage List     Post MessagePost Message

  Text label boxes shift
Posted by Dmitriy on Jan-23-2012 20:01
Attachments:
Hi.

I'm trying to set custom size for pie chart labels to make them a little bigger than automatic sizes. But the label boxes shift from the center of the sector if I set these custom values.

Here is example code. It's the code snippet from ChartDirector documentation with details elided.

int main(int argc, char *argv[])
{
    double data[] = {21, 18, 15, 12, 8, 24};
    const char *labels[] = {"LABEL1", "LABEL2", "LABEL3", "LABEL4", "LABEL5",
        "LABEL6"};

    int colors[] = {0x66aaee, 0xeebb22, 0xbbbbbb, 0x8844ff, 0xdd2222, 0x009900};
    PieChart *c = new PieChart(600, 360);

    c->setPieSize(300, 195, 110);
    c->setData(DoubleArray(data, sizeof(data)/sizeof(data[0])), StringArray(labels,
        sizeof(labels)/sizeof(labels[0])));
    c->setColors(Chart::DataColor, IntArray(colors, sizeof(colors)/sizeof(colors[0])));

    c->setLabelLayout(Chart::SideLayout);

    TextBox *t = c->setLabelStyle("arialbd.ttf", 10, 0x000000);
    t->setBackground(0x348765, Chart::Transparent, Chart::softLighting(
        Chart::Right, 0));

    // this line causes labels shift (pic2)
    t->setSize( 75, 40 );

    c->setLabelPos(-10);

    c->makeChart("pie.png");

    delete c;
    return 0;
}

How can I change the label box sizes and keep the original positions?
pic1.png
pic2.png

  Re: Text label boxes shift
Posted by Peter Kwan on Jan-24-2012 02:09
Hi Dmitriy,

We are aware that the Box.setSize cannot be used in the pie chart labels. Instead, please use CDML to control the size (see the "Exploded Pie Chart" sample code).

For example:

c.setLabelFormat("<*block,halign=center,valign=center,width=75,height=30*>{label}\\n{percent}%");

Hope this can help.

Regards
Peter Kwan

  Re: Text label boxes shift
Posted by Dmitriy on Jan-25-2012 16:57
Hi Peter,

It works. Thank you.