Legend

The Legend for a bar chart is turned on by setting the Legend’s IsVisible property to true and defining the Title attributes for the legend entries. The legend entries are the BarSet objects. The following example is the stacked, grouped bar example with the legend enabled.

 

bar004

(Download Code)

 

using Imsl.Chart2D;

using System.Drawing;

 

public class SampleBarLegend : FrameChart {

 

    public SampleBarLegend() {

        Chart chart = this.Chart;

        AxisXY axis = new AxisXY(chart);

        chart.Legend.IsVisible = true;

        // y is a 2 by 3 by 4 array

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

            new double[3][] {

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

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

                new double[] {1, 5, 3, 8}},

            new double[3][] {

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

                new double[] {4, 1, 7, 2},

                new double[] {8, 5, 6, 1}}};

        Bar bar = new Bar(axis, y);

        bar.BarType = Bar.BAR_TYPE_VERTICAL;

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

        // group 0 - shades of red

        bar.GetBarSet(0,0).SetTitle("Red");

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

        bar.GetBarSet(1,0).SetTitle("Dark Red");

        bar.GetBarSet(1,0).FillColor = Color.DarkRed;

        // group 1 - shades of blue

        bar.GetBarSet(0,1).SetTitle("Blue");

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

        bar.GetBarSet(1,1).SetTitle("Light Blue");

        bar.GetBarSet(1,1).FillColor = Color.LightBlue;

        // group 2 - shades of gray

        bar.GetBarSet(0,2).SetTitle("Gray");

        bar.GetBarSet(0,2).FillColor = Color.Gray;

        bar.GetBarSet(1,2).SetTitle("Light Gray");

        bar.GetBarSet(1,2).FillColor = Color.LightGray;

    }

 

    public static void Main(string[] argv) {

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

    }

}

 



Visual Numerics - Developers of IMSL and PV-WAVE
http://www.vni.com/
PHONE: 713.784.3131
FAX:713.781.9260