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

Message ListMessage List     Post MessagePost Message

  Problem setting barGap with multi-bar chart
Posted by Gabriele on Oct-27-2021 16:31
Attachments:
Hi everyone,

i have a multi-bar chart which is composed by a succession of:
- an orange column alone
- a light orange column that hides a black column behind it (this black column is only visible if its value is higher than the value of the light orange one)

Now, i would like to reduce the bar gaps in order to make the columns wider (i attach both an example of what i came up with and an example of what i would like to achieve).

I tried to set

BarLayer layer = barChart.addBarLayer2(Chart.Side);
layer.setOverlapRatio(1);
layer.setBarGap(0.01,0.01); //<-- this line

But the output chart's column have a very small width (I attach an example of this chart as well), why? How can I achieve the desire chart? Is there something I am missing?

I know that the first value of setBarGap is the gap between bar groups and the second is the gap between bar of the same group so i don't understand what is the cause of the problem I'm facing.

I'm using Java and ChartDirector 6.0

Thanks in advance.
Gabriele
my-chart.png
chart-to-reach.png
small-widht-chart.png

  Re: Problem setting barGap with multi-bar chart
Posted by Peter Kwan on Oct-28-2021 01:39
Attachments:
Hi Gabrieie,

For your case, I am not too sure how your bars are arranged in the code. I am not even sure how many bar layers are there in your code. If there is only one bar layer, how you can make the black column hidden behind the light orange column, and also has another orange column? Does your code use Layer.setXData to manipulate the bar position?

My guess is there are some conflicting configuration confusing ChartDirector. For example, the setOverlapRatio and setBarGap are contradicting - one specifies that the bars should overlap, and the other specifies is a gap between bars, so the bars cannot overlap.

If I were to develop something similar, I would probably use something like the "Multi-Stacked Bar". See:

https://www.advsofteng.com/doc/cdjava.htm#multistackbar.htm

The above example shows horizontal bars. You can change them to vertical columns by removing the swapXY call.

For your case, you can consider light orange + black bar to be a stacked bar. The orange bar can be treated as a stacked bar with one stack.

I have tested with the following code and it produces the attached image:

double[] data0 = {44, 55, 100};
double[] data1 = {97, 87, 167};
double[] data2 = {10, 0, 20};

XYChart c = new XYChart(400, 400);
c.setPlotArea(50, 20, 320, 340, 0xffffff);

BarLayer layer = c.addBarLayer2(Chart.Stack);
layer.setBarGap(0.2, Chart.TouchBar);

layer.addDataGroup();
layer.addDataSet(data0, 0xff8800);

layer.addDataGroup();
layer.addDataSet(data1, 0xffcc99);
layer.addDataSet(data2, 0x000000);

.... output the chart as usual ....


If the above still cannot solve the problem, is it possible to include a complete example by using hard coded data? You can modify my code to reproduce the problem, so I can try to troubleshoot the issue.

Regards
Peter Kwan
chart.png