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

Message ListMessage List     Post MessagePost Message

  Problem with Axis.addZone
Posted by MikeP on Jun-27-2013 03:38
Attachments:
Hello support.

I am trying to create a positive/negative bar chart similar to the demo 'Positive Negative
Bars', except that I have larger values. When I try to add the zones to the y-axis using a
large endValue, the positive zone does not color. The code change to the demo program is
simply:

    double maxValue = 1000000000;

    // Add a light blue (0xccccff) zone for positive part of the plot area
    c->yAxis()->addZone(0, maxValue, 0xccccff);

    // Add a pink (0xffffcc) zone for negative part of the plot area
    c->yAxis()->addZone(-maxValue, 0, 0xffcccc);

I have attached an image of the result that I see.

Is there some arbitrary upper limit to the endValue in the positive direction (not sure why
the negative direction is not affected), or is this simply a bug?

Is there a way to specify an infinite upper/lower bound so that, in effect, I can say all
values greater than startValue get colorA and all values less than startValue get colorB, ie:

    c->yAxis()->addZone(startValue, <some special value>, colorA);
    c->yAXis()->addZone(<some other special value>, startValue, colorB);

As an alternative, could I layout the axes, retrieve the min/max values and then use those
as the zone boundaries to achieve the same effect?

Thanks for your help.
posnegbars.png

  Re: Problem with Axis.addZone
Posted by MikeP on Jun-27-2013 04:00
Attachments:
Hello again.

I was debugging this issue a little more and discovered that the positive color is being
displayed, except it is in the negative direction. It is behind the negative color (thus,
couldn't be seen in my previous example). The following code produces the attached image
in the demo:

    double maxValue = 1000000000;

    // Add a light blue (0xccccff) zone for positive part of the plot area
    c->yAxis()->addZone(0, maxValue, 0xccccff);

    // Add a pink (0xffffcc) zone for negative part of the plot area
    c->yAxis()->addZone(-4, 0, 0xffcccc);

As you can see the light blue color is being drawn in the negative, rather than positive,
direction. Is there some sort of overflow occurring in the endValue? The API lists the
startValue and endValue as doubles, but perhaps that is incorrect?

My guess is that both calls to addZone are suffering from this problem (overflow?), except
that one of them appears correct (the negative zone).
posnegbars.png

  Re: Problem with Axis.addZone
Posted by MikeP on Jun-27-2013 05:15
The code:

    c->layoutAxes();
    c->yAxis()->addZone(0, c->yAxis()->getMaxValue(), k_colorZonePositive);
    c->yAxis()->addZone(c->yAxis()->getMinValue(), 0, k_colorZoneNegative);

works as expected, but I'd still like to know why the other cases were failing and whether or
not this will _always_ work as intended (except in obvious cases, such as double overflow,
should that ever happen (not likely)).

  Re: Problem with Axis.addZone
Posted by Peter Kwan on Jun-28-2013 00:17
Hi MikeP,

I suspect it is a bug in ChartDirector. The cause is numeric overflow.

Internally, in certain code, ChartDirector may uses 32-bit integers to measure pixel distances. So the maximum positive pixel distance is 2148483647 pixels. For your case, I suspect the max value probably translate to a pixel distance bigger than 2148483647, and the value overflowed and is "wrapped" to the negative side.

For you case, the  layoutAxis + Axis.getMinValue + Axis.getMaxValue method should reliably solve the problem, because the max value would not be exceeding ly large to cause overflow.

Regards
Peter Kwan