Click here to Skip to main content
Click here to Skip to main content

What can SmartLabels™ Technology do for me?

By Andrew Bryan, Product Manager, Dundas Data Visualization Inc.

Editorial Note

This article is in the Product Showcase section for our sponsors at CodeProject. These reviews are intended to provide you with information on products and services that we consider useful and of value to developers.

Introduction

Dundas Data Visualization has many powerful features built into Dundas Chart for .NET. One feature, SmartLabels™, allows for a less-cluttered display of data points for a chart to look the way you need.

SmartLabels™ uses a rule-based technology to get collision-free data point labels. Label collisions can occur when there are many points on a chart or when there are points of similar values. Handling this is one of the most difficult tasks any chart can face and it usually fails to meet the human expectation of the chart appearance. In the end, most chart developers will position the labels manually, which may reduce the collisions but will fail in unknown data conditions. This is where Dundas Chart for .NET excels.

Dundas Chart for .NET SmartLabels™ is designed to prevent data point label collisions for most chart types. Figure 1 shows a simple Line-Column chart where each data point displays a value label. This case shows a simple case and is not uncommon in everyday charting. There is not a large number of points. However, they are similar in value. Notice there are several point labels overlapping and two extending outside of the charting area. The trend is obvious to the eye and the Y-axis labels help understand the data, but the overlapping makes the chart difficult to read.

smrtloff.png

Figure 1: Chart without SmartLabels™

By enabling each series with SmartLabels™ technology, a messy, unreadable chart can quickly become one that allows you to visualize your data.

// Enable SmartLabels for each series


foreach(Series series in Chart1.Series)

    series.SmartLabels.Enabled = true;
smrtlon.png

Figure 2: Chart with SmartLabels™

With SmartLabels™ there is no complex algorithm for you to write and you don't need to know anything about the data ranges beforehand. SmartLabels™ just works with little a very limited time investment to produce clean and readable charts.

How to Use SmartLabels™

When using SmartLabels™ you have control over the appearance styling. There are also two categories of SmartLabels™ rules: label movement rules and positioning rules. Let's take a closer look at the properties each category provides.

Appearance Styles

When a data point label is moved far enough away from a data point, a Callout Line may be shown to the point. The property, LabelCalloutStyle, determines how a Callout Line is terminated at the label end of the line. The possible styles for termination end are a Box, an Underline or None (no added styles). Setting the style is simply one line of code.

CalloutStyles.png

Figure 3: Available Callout Styles

// set the callout style to show a box


Chart1.Series["Series1"].SmartLabels.CalloutStyle = LabelCalloutStyle.Box;

There are other style properties that provide control of the appearance of the Callout Line, as well as the inside color of the box (when the LabelCalloutStyle is of a Box type).

// set the callout box back color
Chart1.Series["Series1"].SmartLabels.SmartLabelEndCap = LabelEndCap.Arrow;

// set the callout box back color
Chart1.Series["Series1"].SmartLabels.CalloutBackColor = Color.Khaki; 

// set the callout line color 
Chart1.Series["Series1"].SmartLabels.CalloutLineColor = Color.Black; 

// set the callout to be a solid line 
Chart1.Series["Series1"].SmartLabels.CalloutLineStyle = ChartDashStyle.Solid; 

// set the callout line width of 1 pixel 
Chart1.Series["Series1"].SmartLabels.CalloutLineWidth = 1; 

Movement Rules

The movement rules are the real guts of Dundas Chart for .NET SmartLabels™. They are simple to understand and set the stage for the readable charts. For example, if it has been determined that a label must be moved, the SmartLabel movement rules permit you to specify the moving distances, the allowable moving directions and whether the label is able to exist outside of the plotting area. These are controlled through the use of several moving-related properties. The default movement rules will normally resolve most issues. However, as usual, Dundas Chart for .NET provides developers with significant customization tools, and SmartLabels™ are no exception.

The allowable data point label movement direction is set using the MovingDirections property. This property can be set to a single direction or as a bitwise OR combination to give you complete control of the movement direction. The distance of movement can also be controlled using the MinMovingDistance or MaxMovingDistance properties. These are pixel properties which define a value that specifies the minimum or maximum distance from the data point that data point labels are allowed to be moved. When a data point label needs to be repositioned, the label will be moved by the range of pixels specified.

MovingPicture.png

Figure 4: Moving Distance and Direction Behavior

// set the minimum moving distance Chart1.Series["Series1"]
.SmartLabels.MinMovingDistance = 20; // set the maximum 
moving distance Chart1.Series["Series1"].SmartLabels.MaxMovingDistance = 30;
// set the allowable label moving directions 
Chart1.Series["Series1"].SmartLabels.MovingDirection =  
LabelAlignment.Bottom | LabelAlignment.BottomRight; 

An additional property, the AllowOutsidePlotArea property, sets a value that specifies the extent of how far outside of the plotting area the labels may go. The default value allows labels to extend partially outside (up to 50%), but can also be set to allow full label drawing outside or not at all. When applying SmartLabels™, the drawing outside of labels is used only to provide an additional option to the chart; the chart will only draw outside if the labels cannot be drawn elsewhere without overlapping.

outsideplotarea.png

Figure 5: AllowOutdsidePlotArea Behavior

// set the rule for labeling outside the plot area (Yes, No or Partial) 
Chart1.Series["Series1"].SmartLabels.AllowOutsidePlotArea =  
    LabelOutsidePlotAreaStyle.Partial;

Positioning Rules

Overlapping labels is an obvious condition for when to reposition a label, but there are other conditions such as labels overlapping markers and a rule to hide labels that cannot be repositioned without overlapping elsewhere (without violating the user-defined rules). In the first frame of Figure 6, the markers are permitted to overlap the data point marker. In the second frame, they are not allowed to overlap and, based on the movement rules that were defined for this example, the point label could be placed anywhere else. The result was that the data point label was not drawn at all.

markeroverlap.png

Figure 6: MarkersOverlapping Behavior

// Allow data point labels to overlap data point markers 
Chart1.Series["Series1"].SmartLabels.MarkersOverlapping = true; 
// Hide all labels that cannot be repositioned without 
overlapping Chart1.Series["Series1"].SmartLabels.HideOverlapped = true;

With the API provided and the flexibility of the Dundas Chart for .NET rule-based labeling, unreadable charts need never be shown again!

Want to Know More?

For an interactive demonstration of Dundas Chart for .NET SmartLabels™, download a full evaluation copy of Dundas Chart for .NET Enterprise Edition and experiment with our extensive sample set or visit the Dundas Chart Gallery on our website.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Since 1992 Dundas Data Visualization has been helping companies all over the world visualize their data. Dundas products have a global reputation of being the highest quality, and are all designed, built and tested to meet the strictest requirements that developers and business managers demand.
 
Our showcase product is Dundas Dashboard, an easy-to-integrate digital dashboard software solution. Dundas Dashboard allows for the rapid and collaborative development of performance dashboards, helping companies leverage their business intelligence (BI) solutions.
 
Our web-based dashboard software comes with wizard interfaces, and a unique Dundas DashFlowTM process, allowing for the simultaneous development of an executive dashboard by business analysts, IT staff and database administrators. It also uses premier charts, maps, gauges and graph controls, letting end-users visualize their data as required.
 
Dundas also offers superb, world class consulting services for those companies that do not have the in-house expertise to implement their data visualization projects.
 
The quality of our products in conjunction with our unmatched technical support, numerous awards and years of experience reflect Dundas Data Visualization's commitment to being the best!
Group type: Organisation

3 members


Comments and Discussions

 
Generalnice Pinmembercreanet29-Jun-10 1:12 
GeneralNice PinmemberSavara20-May-09 7:39 
GeneralMy Vote is 4 Pinmemberamgadhs26-Mar-09 1:33 
GeneralRe: My Vote is 4 PinmemberVCSKicks4-May-09 14:18 
Ditto. Very impressive control though.
 
Visual C# Kicks - Free C#.NET articles, resources, and downloads at
http://www.vcskicks.com

GeneralMy vote of 5 PinmemberJosemaproject25-Feb-09 5:45 
GeneralMy vote of 2 PinmemberAlexandre GRANVAUD25-Nov-08 21:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 25 Mar 2008
Article Copyright 2008 by Dundas Data Visualization
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid