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

Message ListMessage List     Post MessagePost Message

  How to set the thickness on the AngularMeter, Polar Chart?
Posted by Yejin on Mar-18-2021 14:21
Attachments:
I want to make two charts like right side of the pictures.


1) AngularMeter
How can I set the thickness of AngularMeter?

2) Polar Chart
How can I set the line width of Area Layer?
I tried setLineWidth(), but it seems like it's not working on the Area Layer.


Thanks!
0318.png

  Re: How to set the thickness on the AngularMeter, Polar Chart?
Posted by Peter Kwan on Mar-18-2021 16:00
Attachments:
Hi Yejin,

1) How can I set the thickness of AngularMeter?

The second and third argument of the BaseMeter.addColorScale method can be used to configure the width of the color scale. For example:

// Color scale from radius = 128 to 78  (128 - 50 = 78)
m->addColorScale(DoubleArray(colorScaleData, colorScaleSize), 128, -50);

See:

https://www.advsofteng.com/doc/cdnet.htm#BaseMeter.addColorScale.htm

ChartDirector is very flexible and can be configured very similar to the meter on the right side of your message. The following is an example. You can see the meter image at the bottom of this post.

BaseChart *semicirclemeter(int /* chartIndex */, const char ** /* imageMap */)
{
    // The value to display on the meter
    double value = 72.55;
    int scaleWidth = 50;

    // Create an AngularMeter object of size 300 x 180 pixels with transparent background
    AngularMeter *m = new AngularMeter(300, 180, Chart::Transparent);

    // Center at (150, 150), scale radius = 128 pixels, scale angle -90 to +90 degrees
    m->setMeter(150, 150, 128, -90, 90);

    // Meter scale is 0 - 100, with major tick every 20 units, minor tick every 10 units, and micro
    // tick every 5 units
    m->setScale(0, 100, 20, 10, 5);

    // Set the tick color to white. Hide the default scale and labels.
    m->setTickLength(-scaleWidth);
    m->setLineWidth(0, 2, 0, 0);
    m->setMeterColors(Chart::Transparent, Chart::Transparent, 0xffffff);

    // Add a color scale to the meter
    double smoothColorScale[] = {0, 0xff3333, 20, 0xff8822, 40, 0xffff00, 60, 0x66ff66, 80, 0x44ccff, 100};
    m->addColorScale(DoubleArray(smoothColorScale, (int)(sizeof(smoothColorScale) / sizeof(
        smoothColorScale[0]))), 128, -scaleWidth);

    // Add labels to the meter
    const char* labels[] = { "20", "40", "60", "80", "100" };
    int labelCount = 5;
    for (int i = 0; i < labelCount; ++i)
    {
        double textAngle = ((i + 0.5) / 5) * 3.1416;
        double x = 150 - (128 - scaleWidth / 2.0) * cos(textAngle);
        double y = 150 - (128 - scaleWidth / 2.0) * sin(textAngle);
        m->addText((int)(x + 0.5), (int)(y + 0.5), labels[i], "arialbd.ttf", 14, 0x000000, Chart::Center);
    }

    // Add a pointer at the specified value
    m->addPointer2(value, 0x555555, 0x555555, Chart::TriangularPointer2, 0, 0.5, 10);

    // Set the meter cap
    m->setCap2(0x555555, 0xffff00, 0xeeee00, 1, 0.18, 0.16);

    // Output the chart
    m->makeChart();

    return m;
}


2) How can I set the line width of Area Layer?

There is an example with thick border included in ChartDirector:

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

Basically, it just adds a line layer using the same data as the area layer to create the thick lines.


Regards
Peter Kwan
testmeter.png