|
Problems with setMeter on an Angular meter |
Posted by Electron Sheperd on Dec-10-2018 03:09 |
|
I'm having a problem creating a band around a meter, and I'm wondering what I'm doing wrong. The code to replicate the problem is:
#include <chartdir.h>
int main(int argc, char *argv[])
{
// Create an AngularMeter object of size 250 x 250 pixels with transparent background
AngularMeter *m = new AngularMeter(250, 250, Chart::Transparent);
// Center at (125, 125), scale radius = 111 pixels, scale angle -145 to +145 degrees
m->setMeter(125, 125, 111, -175, 175);
// Add a red band all the around the meter
m->addZone(0, 100, 95, 111, 0xFF0000);
// Output the chart
m->makeChart("roundmeter.png");
//free up resources
delete m;
return 0;
}
This is based on the code for the "Round Meter" sample from the help, with everything that isn't related to the bug removed. When I run this, I get the "Good" image as attached. However, the red band does not go all the way around the meter, since I am passing -175, 175 into the setMeter call. If I change these parameters to be -180, 180 I get the "Bad" image as attached, with the red band just a very thin line at the bottom of the meter.
How can I add a zone that goes all the around the meter?
|
Re: Problems with setMeter on an Angular meter |
Posted by Peter Kwan on Dec-10-2018 21:34 |
|
Hi Electron,
If you want a complete circle, please use AngularMeter.addRing. In the "Round Meter" sample code, you can see the addRing is used to create the grey ring around the meter.
https://www.advsofteng.com/doc/cdcpp.htm#roundmeter.htm
Hope this can help.
Regards
Peter Kwan |
Re: Problems with setMeter on an Angular meter |
Posted by Electron Sheperd on Dec-10-2018 23:44 |
|
Peter,
We're using addZone to add a donut-style band around the meter, so the band we add won't always go all the way around. It will only be a full ring when the value is at 100%.
I've seen https://www.chartdir.com/forum/download_thread.php?bn=chartdir_support&pattern=donut&thread=1513164302#N1513189473 and that's the sort of item we're creating, but we also need to add a pointer (to indicate a second value) to the gauge, so I don't think we can use a PieChart.
Some experimentation here indicates that if the gauge goes from 0 - 100, calling addZone(0, 99.99999 ...) works as expected, and if I call setScale(0, 100.000001) and then call addZone(0, 100), it also works as expected, so it looks as if for gauges where the start and end angles define a complete circle, ChartDirector is comparing the value to the maximum, and not drawing the zone if they are the same.
Do I need to detect when the addZone would add a full ring and change the call to addRing, or is there a better way to do it? |
Re: Problems with setMeter on an Angular meter |
Posted by Peter Kwan on Dec-11-2018 00:58 |
|
Hi Electron,
If it is easy to detect the full ring condition, I would just check if it is a full ring, and use addRing in such case and addZone in other cases.
If your code will never draw 0% or over 100% (that is, will not create a sector like 20 to 150 where the scale is 0 to 100), you can also try addZone(a, b - 0.000000001). This is visually the same as (a, b) and can avoid the full ring problem.
Regards
Peter Kwan |
|