How is BarItem affected by AxisType?
From ZedGraphWiki
How is BarItem affected by AxisType?
The BarItem is one of several bar types available in ZedGraph. See What are the different bar types? page for details on the different bars. However, the BarItem itself can look dramatically different, depending on the data values and the Axis settings. To demonstrate, consider the following code sample (this sample is consistent with all of the other samples in the Sample Graphs section, and it works with the CSharp Reference Code for Sample Charts):
private void CreateGraph( GraphPane myPane )
{
myPane.Title = "Bar Type Sample";
myPane.XAxis.Title = "Ordinal Axis";a
myPane.YAxis.Title = "Some Data Value";
myPane.XAxis.Type = AxisType.Ordinal;
double[] xArray = { 3, 5, 9, 11, 16, 18 };
double[] yArray = { 10, 45, 78, 34, 15, 26 };
double[] yArray2 = { 54, 34, 64, 24, 44, 74 };
PointPairList list1 = new PointPairList( xArray, yArray );
PointPairList list2 = new PointPairList( xArray, yArray2 );
BarItem bar1 = myPane.AddBar( "First", list1, Color.Blue );
BarItem bar2 = myPane.AddBar( "Second", list2, Color.Red );
myPane.AxisChange( this.CreateGraphics() );
}
This is a basic bar chart that contains two BarItems. The BarItems have common X values, but different Y values. The basic graph appears as follows. Each subsequent image represents another minor change in the settings as described in the text next to the image.
AxisType.OrdinalBy default, the bars are arranged in BarType.Cluster format. Of particular note here is that X axis values represent the Ordinal values (1 for the first item, 2 for the second, etc.) rather than the actual X values. Also, being an Ordinal axis type, the bars are evenly-spaced.
The XAxis can be switch to Text label display (AxisType.Text) with the following code modifications:
string[] labels = { "North", "South", "East", "West", "Up", "Down" };
myPane.XAxis.Scale.TextLabels = labels;
myPane.XAxis.Type = AxisType.Text
AxisType.TextThis graph is essentially identical to the AxisType.Ordinal except that the "1.0, 2.0, 3.0" X axis labels have been replaced by the specified text labels.
Another option is AxisType.LinearAsOrdinal, which plots the data similar to AxisType.Ordinal, but uses the actual data values for the Axis labels. This option is essentially a text axis in which the text labels are the formatted linear data values. To generate this graph, you can remove the TextLabel string settings from the previous graph, and make the following change:
myPane.XAxis.Type = AxisType.LinearAsOrdinalAxisType.LinearAsOrdinal
Note that the data values are { 3, 5, 9, 11, 16, and 18 }, rather than the regular Ordinal axis which has { 1, 2, 3, 4, 5, and 6 }.
So far, all of the different options have been ordinal types, which causes the bars to be equally spaced in spite of the fact that the X data values are not evenly spaced. For the next graph, which will be AxisType.Linear, make the following change:
myPane.XAxis.Type = AxisType.LinearAxisType.Linear
This time, the display changes dramatically. First, the bars are placed at irregular intervals with wide gaps between values 5 and 9, and 11 and 16. This is because the bars are plotted at the actual X data values specified (although still arranged in a clustered format, with the center of each cluster positioned at the X data value). Second, the bars are much thinner. This is because ZedGraph no longer has a way to decide how wide the bars should be to fill the available space. So by default, for any non-ordinal axis type, the width of the BarItem bars will be 1.0 scale units.
In the next graph, we will manually modify the bar width to be a little more reasonable. In this case, the X values are (at minimum) 2.0 units apart, so we will use a cluster width of 2.0 (instead of the default 1.0). This is accomplished with the following code change:
myPane.ClusterScaleWidth = 2.0;AxisType.Linear + ClusterScaleWidth=2
You now see the same display as the previous one, but with wider bars. You can set the GraphPane.BarSettings.ClusterScaleWidth to any value you like, but in this case, if the value is more than 2.0 the bars will start to overlap.
Next, to demonstrate how the X values are used, we will change the X values that are applied to the second BarItem (the red one). To see this, make the following code change to the 'list2' PointPairList:
double[] xArray2 = { 10, 12, 13, 15, 17, 19 };
PointPairList list2 = new PointPairList( xArray2, yArray2 );
As you can see, the X values for the blue bar are different than the X values for the red bar. This gives the following chart:
AxisType.Linear + Red Bar has new X valuesThis time all of the red bars have shifted to new locations to reflect the new X values that were specified. Note that if the X axis were an ordinal type, the bars would look just like the ordinal plots above since the actual values are not used for ordinal types. Another thing to observe is that, even though there is only one bar at any given X value (none of the X's are the same for the red and blue bar), the bars are still arranged in cluster format. For example, the blue bar at X=5 is actually located to the left of 5, since the red bar would normally be on the right of 5, making the 5.0 value sit at the center of the cluster. As a result, with ClusterScaleWidth=2 some of the bars end up overlaying. The red bar which lies to the right of 10 overlays the blue bar to the left of 11.
We can also disable the cluster format so that each bar is individually centered at its specified X location by using the Overlay bar type. In this mode, bars that have the same X value just overlay each other. This is accomplished with the following code change:
myPane.BarType = BarType.Overlay;AxisType.Linear + Red bar has new X + BarType.Overlay
Now all the bars are independently positioned, and centered on their actual X value.
One more option of note is that you can override the ordinal positioning for any ordinal type. That is, your X values can specify ordinal locations. For this to work, the X values must correspond to the normal 1, 2, 3 value positioning, and you must activate the CurveItem.IsOverrideOrdinal property. The following is an example, similar to the previous example chart:
private void CreateGraph( GraphPane myPane )
{
myPane.Title = "Bar Type Sample";
myPane.XAxis.Title = "Text Axis (IsOverrideOrdinal)";
myPane.YAxis.Title = "Some Data Value";
myPane.XAxis.Type = AxisType.Text;
double[] xArray = { 1, 1.8, 3.2, 4, 5, 6 };
double[] yArray = { 10, 45, 78, 34, 15, 26 };
double[] yArray2 = { 54, 34, 64, 24, 44, 74 };
PointPairList list1 = new PointPairList( xArray, yArray );
PointPairList list2 = new PointPairList( xArray, yArray2 );
BarItem bar1 = myPane.AddBar( "First", list1, Color.Blue );
bar1.IsOverrideOrdinal = true;
BarItem bar2 = myPane.AddBar( "Second", list2, Color.Red );
bar2.IsOverrideOrdinal = true;
string[] labels = { "North", "South", "East", "West", "Up", "Down" };
myPane.XAxis.TextLabels = labels;
myPane.XAxis.Type = AxisType.Text;
myPane.AxisChange( this.CreateGraphics() );
}
In this case, the x values for the second and third bars are slightly shifted to demonstrate the effect. Of course, in this mode you can actually place the bars anywhere you like (not just a slight shift).
AxisType.Text + IsOverrideOrdinal
Notice how the second cluster is shifted to the left and the third cluster is shifted to the right. Also note that the bars are still in a clustered format. Actually, the IsOverrideOrdinal mode makes the most sense for non-clustered bars, such as BarType.Overlay.
Checkout research paper writing service.









