JMSL Chart Programmer’s Guide
Grouped Bar Chart
In a grouped bar chart multiple sets of data are displayed as side-by-side bars.
The data argument to the constructor for a grouped bar chart is an nGroups by nItems array of doubles. In this example there are two groups, each containing four items. All of the groups must contain the same number of items.
The getBarSet(int) method returns a BarSet object that is a collection of the BarItem objects that make up a given group. Here the bars in group 0 are set to red and those in group 1 are set to blue.
View code file
 
import com.imsl.chart.*;
import java.awt.Color;
 
public class SampleBarGroup extends JFrameChart {
public SampleBarGroup() {
Chart chart = getChart();
AxisXY axis = new AxisXY(chart);
double y[][] = {{4,2,3,9},{6,7,5,2}};
Bar bar = new Bar(axis, y);
bar.setBarType(Bar.BAR_TYPE_VERTICAL);
bar.setLabels(new String[]{"A","B","C","D"});
bar.getBarSet(0).setFillColor(Color.red);
bar.getBarSet(1).setFillColor(Color.blue);
}
public static void main(String argv[]) {
new SampleBarGroup().setVisible(true);
}
}
In the above grouped bar chart example, the Bar constructor creates a collection of chart nodes. For each group, it creates a BarSet node as its direct child. Each BarSet node has BarItem nodes as children, one for each bar in the set.