Nevron .NET Vision Documentation
Cartesian Axis Anchors

Axis anchors define the axis orientation and placement in the chart area. There are two types of axis anchors – dock and cross axis anchors.

Dock Axis Anchors

When an axis has a dock anchor it is placed in one of the axis dock zones as specified by the anchor. The axis dock zones are positioned on the edges of the chart bounding box and have their names (for example Front Left, Front Right etc).

The following picture shows the most commonly used dock zones of a 3D Cartesian chart.



figure 1.

In 2D only the Front Left, Front Top, Front Right and Front Bottom zones are used.

Nevron Chart for .NET supports three types of dock axis anchors.

Docking Axes to Axis Dock Zones

To enable an axis anchor, you have to create an instance of the desired anchor type and assign it to the Anchor property of the axis. The following code demonstrates how to dock the primary Y axis to the Front Right zone:

C#
Copy Code
NChart chart = chartControl.Charts[0];
NBarSeries bar = (NBarSeries)chart.Series.Add(SeriesType.Bar);
bar.Values.Add(10);
bar.Values.Add(20);
bar.Values.Add(24);

NAxis axis = chart.Axis(StandardAxis.PrimaryY);
axis.Anchor = new NDockAxisAnchor(AxisDockZone.FrontRight, true);
chartControl.Refresh();
Visual Basic
Copy Code
Dim chart As NChart = chartControl.Charts(0)
Dim bar As NBarSeries = chart.Series.Add(SeriesType.Bar)
bar.Values.Add(10)
bar.Values.Add(20)
bar.Values.Add(24)

Dim axis As NAxis = chart.Axis(StandardAxis.PrimaryY)
axis.Anchor = New NDockAxisAnchor(AxisDockZone.FrontRight, True)
chartControl.Refresh()
Axis Dock Zone Levels

Axis dock zones can contain an unlimited number of axes grouped together in zone levels. The axes in one zone level cannot overlap axes in other zone levels in the same dock zone. This is illustrated with the following picture:



figure 2.

On this picture the orange and gray axes share a zone level and the blue axis creates a second zone level on top of the first one. Note that the chart will not allow axes in different zone levels to overlap.

Initially axis dock zones do not contain any levels. When the first axis arrives in the zone it will always create a new level regardless of the setting specified by the CreateNewZoneLevel property of the anchor. Subsequent axes however will have that option – e.g. whether to use the zone level created by the previous axes or create a new one.

Axis Area Percentages

Note that on figure 2 the axes have different height. This is achieved by specifying how much area they use from the space available in the axis dock zone and is specified in code with the help of the BeginPercent and EndPercent properties of the dock anchor. The following code shows how to change the area occupied by an axis in its dock zone:

C#
Copy Code
NAxis axis = chart.Axis(StandardAxis.PrimaryY);
axis.Anchor = new NDockAxisAnchor(AxisDockZone.FrontLeft, false, 0, 30);
Visual Basic
Copy Code
Dim axis As NAxis = chart.Axis(StandardAxis.PrimaryY)
axis.Anchor = New NDockAxisAnchor(AxisDockZone.FrontLeft, False, 0, 30)
Axis Dock Zone Levels Spacing

Each axis dock zone level has spacing applied before all other levels in the zone and spacing that should be leaved after it when other levels are added. These spaces are called BeforeSpace and AfterSpace and can be specified in the dock anchor. The following picture shows a chart with two axis dock zone levels, where the second one (created by the blue axis) has BeforeSpace equal to ten points:



figure 3.

This feature of the dock anchor allows you to have axes that are detached from the chart area.

The following code will alter the before spacing of the primary Y axis:

C#
Copy Code
NDockAxisAnchor dockAnchor = new NDockAxisAnchor(AxisDockZone.FrontLeft, false);
dockAnchor.BeforeSpace = new NLength(10, NGraphicsUnit.Point);
dockAnchor.AfterSpace = new NLength(0, NGraphicsUnit.Point);

NChart chart = chartControl.Charts[0];
NAxis axis = chart.Axis(StandardAxis.PrimaryY);
axis.Anchor = dockAnchor; 
Visual Basic
Copy Code
Dim dockAnchor As NDockAxisAnchor = New NDockAxisAnchor(AxisDockZone.FrontLeft, False)
dockAnchor.BeforeSpace = New NLength(10, NGraphicsUnit.Point)
dockAnchor.AfterSpace = New NLength(0, NGraphicsUnit.Point)

Dim chart As NChart = chartControl.Charts(0)
Dim axis As NAxis = chart.Axis(StandardAxis.PrimaryY)
axis.Anchor = dockAnchor
Cross Axis Anchors

The cross axis anchor allows you to specify the axis orientation (Horizontal, Vertical or Depth) and give the axis a reference point that it must cross. This reference point can be either a value on another axis of the chart (value crossing) or a point specified as aligned offset from the chart area (model crossing).

The following two pictures illustrate how axis crossing works in practice:



figure 4 - Axis Value Crossing



figure 5 - Axis Model Crossing

Axis Value Crossing

To create an axis that crosses another axis on a certain value you need to follow two steps:

1. Create an instance of the NCrossAxisAnchor object and assign it to the Anchor property of the axis.

2. Create an instance of the NValueAxisCrossing object and add it to the Crossings collection of the anchor.

The following code will cross the PrimaryY axis to the value 2 of the PrimaryX axis:

C#
Copy Code
NChart chart = chartControl.Charts[0];

NAxis primaryY = chart.Axis(StandardAxis.PrimaryY);
NAxis primayX = chart.Axis(StandardAxis.PrimaryX);

NCrossAxisAnchor crossAnchor = new NCrossAxisAnchor(AxisOrientation.Vertical);
NValueAxisCrossing valueCrossing = new NValueAxisCrossing(primayX, 2);
crossAnchor.Crossings.Add(valueCrossing);

primaryY.Anchor = crossAnchor;
Visual Basic
Copy Code
Dim chart As NChart = chartControl.Charts(0)

Dim primaryY As NAxis = chart.Axis(StandardAxis.PrimaryY)
Dim primayX As NAxis = chart.Axis(StandardAxis.PrimaryX)

Dim crossAnchor As NCrossAxisAnchor = New NCrossAxisAnchor(AxisOrientation.Vertical)
Dim valueCrossing As NValueAxisCrossing = New NValueAxisCrossing(primayX, 2)

crossAnchor.Crossings.Add(valueCrossing)

primaryY.Anchor = crossAnchor
Axis Model Crossing

Similarly to create an axis that crosses another axis at a certain point along its visual representation you need to follow two steps:

1. Create an instance of the NCrossAxisAnchor object and assign it to the Anchor property of the axis.

2. Create an instance of the NModelAxisCrossing object and add it to the Crossings collection of the anchor.

The following code will position the primary Y axis on the center of the primary X axis area:

C#
Copy Code
NChart chart = chartControl.Charts[0];

NAxis primaryY = chart.Axis(StandardAxis.PrimaryY);
NAxis primaryX = chart.Axis(StandardAxis.PrimaryX);

NCrossAxisAnchor crossAnchor = new NCrossAxisAnchor(AxisOrientation.Vertical);
NModelAxisCrossing modelCrossing = new NModelAxisCrossing(primaryX, HorzAlign.Center, new NLength(0));
crossAnchor.Crossings.Add(modelCrossing);

primaryY.Anchor = crossAnchor;
Visual Basic
Copy Code
Dim chart As NChart = chartControl.Charts(0)

Dim primaryY As NAxis = chart.Axis(StandardAxis.PrimaryY)
Dim primaryX As NAxis = chart.Axis(StandardAxis.PrimaryX)

Dim crossAnchor As NCrossAxisAnchor = New NCrossAxisAnchor(AxisOrientation.Vertical)

Dim modelCrossing As NModelAxisCrossing = New NModelAxisCrossing(primaryX, HorzAlign.Center, New NLength(0))

crossAnchor.Crossings.Add(modelCrossing)
primaryY.Anchor = crossAnchor

Finally the NCrossAxisAnchor also has StartPercent and EndPercent properties and their meaning is the same as described in the Axis Docking section.

Related Examples

Windows Forms: Axes \ General \ Docking

Windows Forms: Axes \ General \ Value Crossing

Windows Forms: Axes \ General \ Model Crossing

Windows Forms: Axes \ General \ Ruler Size

See Also

 

 


©2017. Nevron Software LLC.

Send Feedback