.netCHARTING v5.2 Documentation Send comments on this topic.
Label Alignment and Control
Getting Started > General Tutorials > Using labels > Label Alignment and Control

Glossary Item Box

Introduction

Each element contains a SmartLabel object with properties that affect the label's behavior. To show the element labels the following code can be used. The setting will propagate to all elements within the chart.

[C#]

Chart.DefaultElement.ShowValue = true;

[Visual Basic]

Chart.DefaultElement.ShowValue = True

Absolute Position [New in v5.0]

SmartLabels have the ability to be positioned anywhere on the chart by specifying a static Point object representing the label's desired location.

[C#]

myElement.SmartLabel.AbsolutePosition = new Point(50, 210);
[Visual Basic]

myElement.SmartLabel.AbsolutePosition = New Point(50, 210)
Sample: AbsoluteLabelPosition.aspx

Dynamic Labels

Force Label Drawing
Labels that cannot fit on the chart will not be shown by default. To force them to appear, the DynamicDisplay property must be set to false.

[C#]

Chart.DefaultElement.SmartLabel.DynamicDisplay = false;

[Visual Basic]

Chart.DefaultElement.SmartLabel.DynamicDisplay = False


Prevent Label Overlap
Non-column series type elements have labels which will dynamically move out of each other's way to prevent overlap. When this happens, a line is drawn to indicate which element the label pertains to. This behavior can be turned off and on using the DynamicPosition property. The following code disables this feature:

[C#]

Chart.DefaultElement.SmartLabel.DynamicPosition = false;

[Visual Basic]

Chart.DefaultElement.SmartLabel.DynamicPosition = False

The line drawn to indicate the element can be modified through the SmartLabel.Line property.

Line caps can be used to make the indicator lines look like arrow pointers.

SmartLabel Padding [New in v5.0]

In some cluttered situations where many elements are close together and in turn surrounding labels are close together as well can make the chart more difficult to understand. Using SmartLabel padding will force a gap between the elements and labels, as well as between the labels themselves.

 

[C#]

Chart.DefaultElement.SmartLabel.Padding = 5;
[Visual Basic]

Chart.DefaultElement.SmartLabel.Padding = 5

 

The dynamic nature of SmartLabels positioning can result in complex label layouts. If the layout of these labels is not aesthetically pleasing or undesired, adjusting the padding value can have drastic results and in many cases favorable results.

SmartLabel Maximum Distance Threshold [New in v5.0]

With the dynamic nature of data it is possible for the chart not to be able to find any room for a label near an element, in which case, the label can end up far away from the parent element. Using the SmartLabel.MaximumDistance property allows control over how far a label can move away from the source element.

 

[C#]

Chart.DefaultElement.SmartLabel.DistanceMaximum = 50;
[Visual Basic]

Chart.DefaultElement.SmartLabel.DistanceMaximum = 50
Sample: SmartLabelDistances.aspx

Label Alignment

Element labels also have several other alignment options available provided by the LabelAlignment enumeration.

Alignment
A label's default alignment is controlled with the SmartLabel.Alignment property.

[C#]

Chart.DefaultElement.SmartLabel.Alignment = LabelAlignment.Top;

[Visual Basic]

Chart.DefaultElement.SmartLabel.Alignment = LabelAlignment.Top

Column Labeling

Secondary Alignment
Since there may not always be enough room to place the label in desired position (Alignment). The chart engine will look at the AlignmentSecondary property which is a collection of LabelAlignment objects and find the next best one that fits. The following code clears the default secondary alignment settings and sets two options labels can use.

[C#]

Chart.DefaultElement.SmartLabel.SecondaryAlignment.Clear();
Chart.DefaultElement.SmartLabel.SecondaryAlignment.Add(LabelAlignment.OutsideTop);
Chart.DefaultElement.SmartLabel.SecondaryAlignment.Add(LabelAlignment.Bottom);

[Visual Basic]

Chart.DefaultElement.SmartLabel.SecondaryAlignment.Clear()
Chart.DefaultElement.SmartLabel.SecondaryAlignment.Add(LabelAlignment.OutsideTop)
Chart.DefaultElement.SmartLabel.SecondaryAlignment.Add(LabelAlignment.Bottom)

Vertical Label
When a label doesn't fit into a column horizontally it will try to fit vertically. If the label is too tall to fit, the label font will decrease in size until it fits. For cases where columns have both horizontal and vertical labels, column labels may be difficult to read. If this is the case, all labels can be forced to show vertically by using this code:

[C#]

Chart.DefaultElement.SmartLabel.ForceVertical = true;

[Visual Basic]

Chart.DefaultElement.SmartLabel.ForceVertical = True

Note: This feature doesn't affect horizontal charts.
©2008. All Rights Reserved.