The first layout stage is called Initial Positioning. It can be enabled with the following code:
C# |
Copy Code
|
---|---|
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 label's locations.
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 NDomArray<ENLabelLocation>(new ENLabelLocation[] { ENLabelLocation.Top, ENLabelLocation.Bottom }); |
The order of the location proposals in the array determines their priority. The first proposed location has the 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. By default, all eight locations are enabled for each series, but you can reduce this number if the results are good enough with fewer 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;
|
The chart series provides settings for fine control over the proposed label locations that fall outside the plot area. The OutOfBoundsLocationMode property specifies how “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 the 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.
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.
Naturally, the "Initial Positioning" stage cannot avoid all label overlaps. It may happen that for some 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;
|