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

Message ListMessage List     Post MessagePost Message

  Cant figure out why I'm getting wide bars
Posted by MarkZB on Jun-22-2018 20:51
Attachments:
Hi Peter

Any thoughts on why this is happening?
WideBars.png

  Re: Cant figure out why I'm getting wide bars
Posted by MarkZB on Jun-22-2018 21:14
Attachments:
Here's a closer slice...

also - Is there a way to avoid  number duplication in the labels?
WideBarsCloser.png

  Re: Cant figure out why I'm getting wide bars
Posted by Peter Kwan on Jun-22-2018 22:05
Hi MarkZB,

For your current data, it is confusing what the bars should look like. A bar is not a point. It has a width. Suppose you have 5 bars at x = 10, 20, 30, 40, 50. So how wide the bars should be? If the bar width is 10 units, then the first bar should start from 5 and ends at 15. The second bar will be from 15 to 25 and so on. So the edge of a bar can start from 5 and 15 even if there is no data point at x = 5 or 15. That explains why in the chart a bar starts from 8, even there is "no 8 in x-axis data". In fact, the edge of a bar normally is at a position with no data.

Suppose you have a chart with bars at x = 10, 17.9, 25, 33.1, 45. How wide should the bars be? It would be confusing. Currently, your data are like the above, with evenly spaced x coordinates.

Furthermore, it is likely you have configured the bar chart to force all bars to touch each others with no gap in between. So the only option is for every bar to have different width. Consider the bar at x = 17.9 above. Since the left edge of that bar must touch the right edge of the previous bar at x = 10, so the most reasonable position of the edge must be at the midpoint between the two bars, or at (10 + 17.9) / 2 = 13.95. As a result, you should see the second bar starts from x = 13.95.

The above is why it is common not to provide x-coordinates for the bars. It is because if the x-coordinates are not even spaced, the bar width becomes confusing. If the x-coordinates are evenly spaced, then it is not necessary to provide the x-coordinates at all. You can just use a label based x-axis.

So instead of using

x = {1, 2, 3, 4, 12, 14}
y = {0.024, 0.044. 0.045, 0.000500745, 0.072, 0.0017526075}

you can use:

y = {0.024, 0.044. 0.045, 0.000500745, 0, 0, 0, 0, 0, 0, 0, 0.072, 0, 0.0017526075}

So the code is like:

BarLayer layer = c.addBarLayer(y);

The x-axis labels can be set to any text strings you like using Axis.setLabels. This would be like the "Simple Bar Chart" in the ChartDirector sample code.

However, if you must use setXData for variable bar spacing, and if you want the bars to touch each others, then by the bars must have variable width, otherwise they cannot touch. If you want to bars to have fixed widths, some of the bars would not touch. As explained above, the bar width is confusing, and ChartDirector can only guess the width. So it is better for your code to use BarLayer.setBarWidth to specify the width.

Hope this can help.

Regards
Peter Kwan

  Re: Cant figure out why I'm getting wide bars
Posted by MarkZB on Jun-22-2018 22:49
Attachments:
Thanks Peter

I disabled barLayer.setBarGap(Chart.TouchBar) and am now setting bar width manually.

Is there a way to not get duplicate X labels?
duplicatelabels.png

  Re: Cant figure out why I'm getting wide bars
Posted by MarkZB on Jun-22-2018 21:22
Here's the data:

X Name Value Type
[0] 1 double
[1] 2 double
[2] 3 double
[3] 4 double
[4] 12 double
[5] 14 double

Y Name Value Type
[0] 0.025 double
[1] 0.044 double
[2] 0.045 double
[3] 0.000500745 double
[4] 0.072 double
[5] 0.0017526075 double

  Re: Cant figure out why I'm getting wide bars
Posted by Peter Kwan on Jun-23-2018 01:31
Hi MarkZB,

I suspect the labels are at x = 1, 1.5, 2, 2.5, 3 .... You may have a line of code that formats the numbers to no decimal place. After formatting, the labels become 1, 2, 2, 3, 3, ....

We need to determine why there would be labels on the x-axis in the first place. It can be specified by your code, or it can be due to auto-scaling by ChartDirector.

Normally, if it is auto-scaled, ChartDirector would not put so many labels on the x-axis, unless the code configures the axis to use denser labels with Axis.setTickDensity. In this case, you may consider not to make the label that dense, or you can use Axis.setMinTickInc to specify a minimal tick increment of 1 (so the ticks would not have 0.5 unit increment).

If the labels are directly specified by your code (eg. using Axis.setLinearScale with the tick increment specified), please modify your code to ensure the tick increment is an integer.

Hope this can help.

Regards
Peter Kwan

  Re: Cant figure out why I'm getting wide bars
Posted by MarkZB on Jun-23-2018 01:52
Thank you. Axis.setMinTickInc(1) did the trick