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

Message ListMessage List     Post MessagePost Message

  Polar Area Chart
Posted by Alex on Aug-12-2023 02:10
Hello dear community! Could you tell me please is it possible to automatically or manually set the lables degree to rotate it around the Polar Area Chart (360)? I am using Chart Director 7.0, C++ MFC.

  Re: Polar Area Chart
Posted by Peter Kwan on Aug-12-2023 14:52
Attachments:
Hi Alex,

Yes. you can rotate the labels. The exact details depend on how do you want to rotate the labels. The attached image is one possible way.

The most flexible way to rotate a label is to use BaseChart.addText to add the label. The code that produces the angular axis labels in the attached image is as follows:

// Set angular axis using the given labels. *** Hide the labels by setting their
// colors to Chart::Transparent.
c->angularAxis()->setLabels(StringArray(labels, labels_size))->setFontColor(Chart::Transparent);

// Use a loop to add the labels with our own code. We need to determine
// the rotation angle and the position of the label with code.
for (int i = 0; i < labels_size; ++i) {
    TextBox* t = c->addText(0, 0, labels[i], "Arial Bold", 10);
    double extraRadius = t->getHeight() / 2.0 + 10;
    double x = 230 + (180 + extraRadius) * sin(-i * 2 * 3.1415926536 / labels_size) + 0.5;
    double y = 280 - (180 + extraRadius) * cos(-i * 2 * 3.1415926536 / labels_size) + 0.5;
    t->setPos(x, y);
    t->setFontAngle(360.0 * i / labels_size);
    t->setAlignment(Chart::Center);
}

Best Regards
Peter Kwan
polararea.png

  Re: Polar Area Chart
Posted by Alex on Aug-12-2023 19:59
Attachments:
Peter, thank you very much for a quick reply! I attached the picture with the angles i need around the polar chart, something like you showed but with 90 degree towards the polar chart area, it would be great if you post a code example how to rotate the lables as i need.

Thank you!!!
Test.JPG

  Re: Polar Area Chart
Posted by Peter Kwan on Aug-14-2023 16:14
Attachments:
Hi Alex,

The code is similar. You just need to modify the rotation angle to implement the rotation you want to use.

c->angularAxis()->setLabels(StringArray(labels, labels_size))->setFontColor(Chart::Transparent);

for (int i = 0; i < labels_size; ++i) {
    TextBox* t = c->addText(0, 0, labels[i], "Arial Bold", 10);
    double extraRadius = t->getWidth() / 2.0 + 8;
    double angle = 360.0 * i / labels_size;
    double x = 230 + (180 + extraRadius) * sin(-angle * 2 * 3.1415926536 / 360) + 0.5;
    double y = 280 - (180 + extraRadius) * cos(-angle * 2 * 3.1415926536 / 360) + 0.5;
    t->setPos(x, y);
    t->setFontAngle(angle + ((angle < 179) ? -90 : 90));
    t->setAlignment(Chart::Center);
}

Best Regards
Peter Kwan
polararea.png

  Re: Polar Area Chart
Posted by Alex on Aug-15-2023 09:10
Hi Peter, that is exactly what i need!!! Thank you very much