The class Bar is used to create bar charts and histograms. This page describes the construction of labeled bar charts. For a discussion of histograms, see Histogram.
The following code creates this labeled bar chart. The BarType attribute can be either BAR_TYPE_VERTICAL or BAR_TYPE_HORIZONTAL. The method SetLabels sets the bar labels and adjusts the attributes of the axis to be appropriate for bar labels. The SetLabels method must be called after the BarType method, so that the correct axis has its attributes adjusted.
The drawing of the bars is controlled by the FillType and FillOutlineType attributes. By default FillType has the value FILL_TYPE_SOLID, so setting the associated attribute FillColor to red causes solid red bars to be drawn.
using Imsl.Chart2D;
using System.Drawing;
public class SampleBar : FrameChart {
public SampleBar() {
Chart chart = this.Chart;
AxisXY axis = new AxisXY(chart);
double[] y = new double[] {4, 2, 3, 9};
Bar bar = new Bar(axis, y);
bar.BarType = Bar.BAR_TYPE_VERTICAL;
bar.SetLabels(new string[] {"A","B","C","D"});
bar.FillColor = Color.Red;
}
public static void Main(string[] argv) {
System.Windows.Forms.Application.Run(new SampleBar());
}
}
The BarGap attribute sets the gap between bars in a group. A gap of 1.0 means that space between bars is the same as the width of an individual bar in the group. Its default value is 0.0, meaning there is no space between groups.
The BarWidth attribute sets the width of the groups of bars at each index. Its default value is 0.5. If the number of groups is increased, the width of each individual bar is reduced proportionately.
See Histogram for an example of the use of the BarWidth attribute.
PHONE: 713.784.3131 FAX:713.781.9260 |