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

Message ListMessage List     Post MessagePost Message

  Digital Bar Chart Issue
Posted by Digital Bar Chart on Nov-14-2016 20:36
Attachments:
Dear all,

I want to make a Bar chart whose axis is a digital axis.

Then I use the api "Layer::setXData" to set the bar range,

but I will alway get a "gap" between the correct bar start point.

For example, I want to make my bar data arrange from 30 - 55 (5 data totally).


Then I use below code:

BarLayer *barLayer= c->addBarLayer(DoubleArray(some_data, count), 0x6699bb);
barLayer->setXData(30+ 2.5, 55 - 2.5);  // 2.5 is the offset
c->addLineLayer()->setXData(0, 100);
c->xAxis()->setIndent(false);


But I found I will always get a "gap" at the point "30" & "55".

You can check the zoomin chart "2.png" for detail.

I don't know why there are such "gap".

Does any one know, how to avoid such "gap"?

Or there are other way for drawing bar chart whose axis is digital axis?

BTW, I use C++ for developing these chart, and chartdirector version is "5.1".


Thanks,
Jeremy
2.png
1.png

  Re: Digital Bar Chart Issue
Posted by Peter Kwan on Nov-15-2016 05:00
Hi Jeremy,

If you use setXData, the horizontal position of the bars are arbitrary. For example, then can be at (3, 5, 7.129, 10.1724, 12). So the bar width may not be determined by the bar position as the latter can be irregular. ChartDirector normally would determine the bar width based on the number of bars and the plot area width.

For your case, the setXData only position the center of the bars to be at (32.5, 37.5, 42.5, 47.5, 52.5). It is likely the bars would not exactly "touch" each others, that is, the bar width is likely not to be exactly 5 x-units. As your chart shows that the bars touch each others, does your code include a line that calls "setBarGap(Chart::TouchBar)" to force the bars to touch each others?

If Chart::TouchBar is in effect, the left and right edges of the bar would be adjusted to touch each others. The left and right edges can be adjusted differently because the spacing to the left and right bars can be different (the bars can be irregularly spaced with setXData).

For your case, for the first bar (at x = 32.5), the right edge is adjusted to touch the next bar at x = 37.5. The left edge is not adjusted as there is no bar to the left, and the y-axis is too far away. (If the y-axis is nearby, the left edge will be adjusted to touch the y-axis.) So the left edge stays at its original position, which happened to be not at x = 30.

To achieve what you need, there are two methods:

(a) Use ChartDirector 6: ChatDirector 6 includes special code that checks for this kind of cases and would adjust the left edge to x = 30 for your case.

(b) If you prefer to use earlier versions of ChartDirector, you can add two more dummy bars to the left and right side. So there would be 7 bars in total, with the leftmost and rightmost bars being 0 or Chart::NoValue and are therefore invisible. The setXData needs to be adjusted to setXData(30 - 2.5, 55 + 2.5) for the 7 bars. This ensures the bar at x = 32.5 has a dummy bar on the left and so its left edge will be adjusted. If the first bar happens to be at x = 0.5 (intsead of 32.5), then no dummy bar is needed as the left edge will be adjusted to touch the y-axis.

Hope this can help.

Regards
Peter Kwan

  Re: Digital Bar Chart Issue
Posted by Digital Bar Chart on Nov-15-2016 19:55
Attachments:
Hi Peter,

Thanks a lot for your reply.

So this should be a bug for chartdirector 5.X version?

We use chartdirector as a basic plot module for our product, and we wrap chartdirector interface to a high level api.

we can't add such dummy bar data for this case, because we need to change related "label, color, name" setting module (also adding dummy data for them).

I considering if we can use the "addAreaLayer" to fake a bar like chart.

Like the example:



Thanks,
Jeremy
1.png

  Re: Digital Bar Chart Issue
Posted by Peter Kwan on Nov-16-2016 00:58
Hi Jeremy,

We have changed the way ChartDirector determines the bar width in ChartDirector 6.0. In all previous versions of ChartDirector, the bar width is determined using a different method. We do not consider the previous bar width determination method to be a bug.

In the Variable Width Bar Chart" sample code, using the original data, the code computes some new values to be used by the addAreaLayer to produce the effect of a "variable width bar chart". You may also consider to use similar method to compute new values to be passed to the addBarLayer, where the new values are just the same as the old values plus some dummy values. If the modification is done at the charting code level, it may affect higher level code.

Regards
Peter Kwan

  Re: Digital Bar Chart Issue
Posted by Digital Bar Chart on Nov-16-2016 19:40
Hi Peter,

Thanks for your advice.
I will consider both method and choice the one change our code the least.


Thanks,
Jeremy