What does 'Ordinal' mean?

From ZedGraphWiki

Jump to: navigation, search

The concept of the 'ordinal' axis type probably results in more questions than any other ZedGraph concept. However, once you understand the underlying purpose, it's not so bad. An ordinal axis is a type of axis in which the actual values of the points are not significant and not used. Internally, ZedGraph is effectively assigning ordinal values to each point and ignoring the values provided by the user (for that axis). The internal ordinal values are 1.0 for the first point, 2.0 for the second, 3.0 for the third, etc.

The ordinal axis type is chosen by setting Axis.Type = AxisType.Ordinal. The following types are all ordinal:

Ordinal graphs have one very significant difference from non-ordinal graphs -- the data are always evenly spaced. For example, take a graph with four data points of {10,50}, {11,24}, {20,75}, and {21,62}. Use the following code to plot the graph (comment out the AxisType.Ordinal assignment to get the linear graph):

GraphPane myPane = new GraphPane( new RectangleF( 0, 0, 300, 200 ), "Ordinal Demo",
                        "X Value (ordinal)", "Y Value" );

PointPairList list = new PointPairList();
list.Add( 10, 50 );
list.Add( 11, 24 );
list.Add( 20, 75 );
list.Add( 21, 62 );

LineItem myCurve = myPane.AddCurve( "Curve", list, Color.Blue, SymbolType.Diamond );
myCurve.Symbol.Fill = new Fill( Color.White );
myPane.XAxis.Type = AxisType.Ordinal;
myPane.AxisChange( this.CreateGraphics() );

The graph on the left is plotted with a linear X axis, and the graph on the right is plotted with an ordinal X axis:

Image:faq_ordinal_lin.png Image:faq_ordinal_ord.png

Notice how both graphs honor the Y values at each point (the Y axis in this case is AxisType.Linear), but only the linear X axis (left graph) honors the X values. The ordinal X axis replaces the original X values with just ordinal (sequential) numbers starting at 1.0. As a result, the ordinal graph values are evenly spaced and the linear graph values are not.

Why would you want an ordinal axis? There are many reasons for this; one being the obvious issues with plotting on a text axis (there are no values). Another example would be the case of a chart of stock prices in which you want to plot the prices on a continuous graph, and you don't want any gaps to show up for weekends, holidays, etc. If you use the AxisType.DateAsOrdinal you will get evenly spaced values, only at the dates for which you have data points.

If you desire, you can override the ordinal behavior on an individual curve basis using the CurveItem.IsOverrideOrdinal property. In this case, you must provide ordinal values that make sense for the axis. In the example above, if you plotted the ordinal graph and activated IsOverrideOrdinal on the curve, you would not see any points because the curve scale would be set up for ordinal values from 1 to 4, but the actual data points are from 10 to 21. Note that this is always the case, the ordinal values start at 1.0, incrementing by 1.0 for the number of items available. This also applies to AxisType.Text. You can plot in between the ordinal value labels using fractional values (1.5 will be placed between the first and second label on the axis).