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 double. 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 BarItems 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.


(Download Code)


using Imsl.Chart2D;

using System.Drawing;


public class SampleBarGroup : FrameChart {


    public SampleBarGroup() {

        Chart chart = this.Chart;

        AxisXY axis = new AxisXY(chart);


        double[][] y = new double[2][] {

           new double[] {4, 2, 3, 9},

           new double[] {6, 7, 5, 2}};

        Bar bar = new Bar(axis, y);

        bar.BarType = Bar.BAR_TYPE_VERTICAL;

        bar.SetLabels(new string[] {"A","B","C","D"});

        bar.GetBarSet(0).FillColor = Color.Red;

        bar.GetBarSet(1).FillColor = Color.Blue;



    public static void Main(string[] argv) {

        System.Windows.Forms.Application.Run(new SampleBarGroup());




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.

Visual Numerics - Developers of IMSL and PV-WAVE
PHONE: 713.784.3131