Chart for .NET / User's Guide / Chart Types / Automatic Data Label Layout
Automatic Data Label Layout

Nevron Chart for .NET provides functionality for automatic layout of data point labels. The objective of this feature is to ensure maximum visibility for chart elements by preventing data point labels from overlapping with each other and with the data points themselves.

Automatic Data Label Layout is supported by Cartesian, Polar and Radar charts. It is performed on two stages that can work independently or in combination. By default both layout stages are disabled. They are activated on a per-chart basis so all data point labels displayed in a given chart are subject to automatic layout. The following images demonstrate a 2D Line chart and a 3D Point chart with enabled Automatic Data Label Layout:





 Initial Positioning

The first layout stage is called Initial Positioning. It can be enabled with the following code:

C#
Copy Code
NChart chart = nChartControl1.Charts[0];
chart.LabelLayout.EnableInitialPositioning = true;
Visual Basic
Copy Code
Dim chart as NChart = nChartControl1.Charts[0];
chart.LabelLayout.EnableInitialPositioning = True

The purpose of Initial Positioning is to select a position for each label from a set of proposed locations situated around the origin point of the label. The control selects the location that causes minimum potential conflicts with other labels locations. The following images illustrate the effect of Initial Positioning on two overlapping data labels:


Initial Positioning Disabled Initial Positioning Enabled


Up to eight location proposals can be specified separately for each series. For example in a chart with two series – line and bar, you can allow the line data labels to go in all eight directions (top, bottom, left, right, top-left, top-right, bottom-left, bottom-right) and at the same time the bar labels can be restricted to just “top” and “bottom” so that they appear either above or below the label origin point. The following code demonstrates how to set the label location proposals for a series:

C#
Copy Code
series.LabelLayout.LabelLocations = new LabelLocation[]
{
    LabelLocation.Top, LabelLocation.Bottom
};
Visual Basic
Copy Code
series.LabelLayout.LabelLocations = New LabelLocation() {LabelLocation.Top, LabelLocation.Bottom}

The order of the location proposals in the array determines their priority. The first proposed location has highest priority, which means that it will be selected unless it causes more conflicts than any of the following proposed locations.

The number of proposed locations determines the capability of the layout to avoid overlaps, but also affects the layout performance to some extent. By default all eight locations are enabled for each series, but you can reduce this number if the results are good enough with less proposed locations.

It is possible to disable the Initial Positioning on a per series basis. If you set the UseLabelLocations property to false, the position of each data label will be determined by the NDataLabelStyle object that is responsible for the label:

C#
Copy Code
series.LabelLayout.UseLabelLocations = false;
Visual Basic
Copy Code
series.LabelLayout.UseLabelLocations = False

The chart series provide settings for fine control over the proposed label locations that fall outside the plot area. The OutOfBoundsLocationMode property specifies how such “out-of-bounds” proposed locations should be treated. There are options to ignore them, use them with their original position, or shift them within the plot bounds. If all of the proposed locations are ignored the control can invert the locations automatically so that there is another chance for the label to be displayed. For example in case of a bar chart where labels are allowed to go only above the bars it is likely that the label of the highest bar will fall partially or fully outside the plot area bounds. If the InvertLocationsIfIgnored property is enabled, the proposed “top” location for this label will be inverted and the label will go downwards instead of upwards. The following images illustrate this scenario:


InvertLocationsIfIgnored = false InvertLocationsIfIgnored = true

Another ability related to label locations is to invert the proposed locations for inverted data points. This is useful for charting types that display oriented data points like for example bar and area charts. The option is enabled through the InvertLocationsForInvertedDataPoints property. The following images illustrate the effect of this feature:


InvertLocationsForInvertedDataPoints = false InvertLocationsForInvertedDataPoints = true

Naturally the Initial Positioning stage cannot avoid all label overlaps. It may happen that for some of the labels none of the proposed locations is applicable. You can instruct the chart to remove such labels for which the Initial Positioning stage has not been able to find an acceptable position. You can enable this option with the following code:

C#
Copy Code
chart.LabelLayout.RemoveOverlappedLabels = true;
Visual Basic
Copy Code
chart.LabelLayout.RemoveOverlappedLabels = True

If you prefer to keep all labels visible the second stage of the layout will try to handle the overlaps with a different approach.

 Label Adjustment

The second stage of the Automatic Data Label Layout is called Label Adjustment. It can be enabled with the following code:

C#
Copy Code
chart.LabelLayout.EnableLabelAdjustment = true;
Visual Basic
Copy Code
chart.LabelLayout.EnableLabelAdjustment = True

This stage removes overlaps by shifting overlapping labels apart from each other. The following images illustrate the effect of Label Adjustment on two overlapping data labels:


Label Adjustment Disabled Label Adjustment Enabled

Label Adjustment can be used regardless of whether Initial Positioning is enabled or not. It applies to all data labels in a chart and cannot be disabled on a per series basis.

 Data Point Safeguard

An important ability of the automatic data label layout is to protect chart data points from being overlapped by data labels. This feature is called Data Point Safeguard and can be enabled or disabled on a per series basis with the following code:

C#
Copy Code
series.LabelLayout.EnableDataPointSafeguard = true;
Visual Basic
Copy Code
series.LabelLayout.EnableDataPointSafeguard = True

Each data point internally defines one or several characteristic points that must be protected from overlaps. The size of the protected area around these points can be specified through the DataPointSafeguardSize property. The safeguard area is regarded by both stages of the automatic layout.

See Also