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

Message ListMessage List     Post MessagePost Message

  Setting bar width with grouped bars (addBarLayer2 & setBarWidth)
Posted by boubekki on Mar-13-2017 21:52
Attachments:
We are trying to generate a chart that grows with the number of bars ie. with fixed bar width.

BarLayer.setBarWidth work well with a single dataset but doesn't with addBarLayer2 and multiple dataset.

In the following example we want to set the width of the bars (and subbars).

We set 20 as the subwidth with a size of 60 for the group because there's 3 value for each group
and 3 * 20 = 60.

The total size of the plot area is 900 - 100 = 800 both sides. There's 2 dataset of 3 values so the real width of the graph should be 2 * 60 = 120. But that's not what happens chartdirector takes all the space available.
plot.py
plot.py

1.17 Kb

  Re: Setting bar width with grouped bars (addBarLayer2 & setBarWidth)
Posted by Peter Kwan on Mar-14-2017 01:51
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