Hi boubekki,
The setBarGap sets the gap between the bars. The setBarWidth sets the width of the bar. They are in conflicting each others, so only one of them will be used (the last one in your code, which is setBarGap).
The plot area can contain many layers of different types. Instead of adjusting the plot area to fit the various layers, the layers will need to fit into a common plot area. For your case, your code sets the plot area to 850 pixels wide, so the plot will be 850 pixels wide.
The x-axis will be configured taken into account the x-axis range of all the layers. For your case, the x-axis only has two positions, which will be distributed evenly on the x-axis (bottom border of the plot area).
If you set the bar group to be 60 pixels, and the 3 sub-bars to be 20 pixels each, there will be no gap between the sub-bars. However, there will be a wide gap between the bar groups because the plot area is 850 pixels wide as specified by your code, but the two bar groups are only 60 pixels wide.
If you set the bap group to touch bar, ChartDirector to stretch the bars so that there is no gap. It means the bar must be much wider to fill the plot area width.
In your case, if you want the plot area width to grow with the number of bars, you may directly set the plot area width to grow with the number of bars. For example:
plotAreaWidth = 20 * barGroupCount * subBarCount
c = XYChart(plotAreaWidth + 50, 900)
c.setPlotArea(50, 50, plotAreaWidth, 800)
layer = c.addBarLayer2(Side)
layer.setBarGap(TouchBar)
.....
Hope this can help.
Regards
Peter Kwan |