.netCHARTING v5.2 Documentation Send comments on this topic.
Using labels
See Also
Getting Started > General Tutorials > Using labels

Glossary Item Box

Introduction

.netCHARTING label strings can be used as dynamic templates capable of evaluating mathematical expressions, embedding info about the associated object, and specifying format strings. They can also include layout and embedded font styling information and links. Images can be used inside labels mixed in with text and dynamic streaming charts generated by aspx pages among other features.

Label is a very powerful object that includes a great deal of functionality. This is an overview list of label related features:

Feature Description
Tokens (Reference) Tokens can be used to embed information about the object associated with the label.
Expressions Mathematical expressions can also be evaluated within label text intertwined with tokens.
Formatting Formatting values.
SmartLabel behavior SmartLabel functionality and behavior features.
Embedded Styling/Images Markup Embedding font styling, images, dynamic streaming charts, and layout information by specifying it within the label text.
InfoGrids™ InfoGrids™ produce results similar to data grid controls; however, they are created and drawn within the chart image itself.
MicroCharts MicroCharts are defined using a markup language inside the label text.

 

The following diagram demonstrates the properties used to access different labels. 

ShowChart Labels Diagram

 

Click on any property name for additional information.

 

Handling Oversized Labels

The axis tick labels use very advanced algorithms to display labels and provide automatic label wrapping, however, not all labels wrap automatically. There are two ways to remedy issues when long labels are becoming a problem. One way to deal with this is to use label truncation. This feature is accessed through the Label.Truncation property. This feature allows limiting the label text to a specified number of characters.

See sample LabelTruncation.aspx for more info.

Most labels will allow automatic wrapping where the label will dynamically determine when and where to wrap text. This feature must be turned on as shown below:

 

[C#]
Chart.DefaultElement.SmartLabel.AutoWrap = true;
[Visual Basic]
Chart.DefaultElement.SmartLabel.AutoWrap = True
Samples: AutoWrapLabels.aspx
PieLabelSmartWrapping.aspx

Labels that dont support automatic wrapping can also be wrapped, however, this must be done manually and is achieved by inserting a new line character into the text of the label.

Tokens

Syntax: %{Token}
Example: %Name

Tokens can be used to embed information about the object associated with the label. For example the label of an element can contain the '%Name' token. When parsed, the token will evaluate to the element's name. The Label Token Reference lists objects and the tokens that are available for each.

 

Sample: ElementTemplate.aspx
Custom Tokens
Custom tokens can also be used to represent miscellaneous information retrieved from a database. For more information on custom tokens see the Custom Attributes tutorial.

 

Expressions

Syntax: <{Expression}>
Example: <(%YValue+5)/ %PercentOfTotal>

Mathematical expressions can also be evaluated within label strings. An expression must be encapsulated within '<' and '>' characters, similar to an xml tag. An example of a simple expression is '<2+2>' which would result in '4' in the final label text. If this expression string is intended to be taken literally, a preceding '\' character will prevent the expression parser from evaluating it. For example the string '\<2+2>' would result in '<2+2>'. Expressions can group parts of the expression using parentheses: (). Example:  <(5+5)*3>. Expressions can also include tokens as values, for example: <%YValue/3>

 

Caution: Spaces are not allowed within expressions.
Wrong: <5 + %YValue>
Correct: <5+%YValue>


Expression Functions

Besides simple expressions, labels can evaluate advanced functions such as sin, cos, or sqrt.

[C#]

Chart.DefaultElement.SmartLabel.Text = "<%YValue+sin(%YValue)>";
[Visual Basic]

Chart.DefaultElement.SmartLabel.Text = "<%YValue+sin(%YValue)>"

This table lists the available functions.

abs(n) Evaluates the absolute value of n.
acos(n) Evaluates the arc cosine of n.
asin(n) Evaluates the arc sine of n.
atan(n) Evaluates the arc tangent of n.
cos(n) Evaluates the cosine of n.
cosh(n) Evaluates the hyperbolic cosine of n.
exp(n) Evaluates the exponent of n.
ln(n) Evaluates the natural logarithm of n.
log(n) Evaluates the logarithm of n (base 10). Same as logn(n,10)
logn(n1,n2) Evaluates the logarithm of n1 where n2 is the base of the logarithm.
sin(n) Evaluates the sine of n.
sinh(n) Evaluates the hyperbolic  sine of n.
sqrt(n) Evaluates the square root of n.
tan(n) Evaluates the tangent of n.
tanh(n) Evaluates the hyperbolic cosine of n.
round(n) Rounds the number leaving no decimals.


 

Embedded Format Strings (In-Line Formatting)

Syntax: <<[expression]> | [token], [Format string]>
Example: <%YValue,Currency>

Values can be formatted in-line within the label using the above syntax.

For more information on in-line formatting see the Advanced Formatting tutorial.

 

Token, Expressions, and In-Line Formatting Examples

The following examples will demonstrate tokens, expressions, and embedded format strings usage.

Label Text Result
%YValue 5
%Name Element 2
<%YValue+5> 10
<(10+5)-%YValue> 10
<sqrt(%YValue)+10> 12.23
<%YValue,Currency> $5.00

<<(10+5)-%YValue>,Currency>

Notice that the expression is encapsulated in <> characters inside the in-line formatting <> tags.

$10.00


 

See Also

©2008. All Rights Reserved.