.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:
|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.|
|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.
|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
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 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.
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>
Besides simple expressions, labels can evaluate advanced functions such as sin, cos, or sqrt.
Chart.DefaultElement.SmartLabel.Text = "<%YValue+sin(%YValue)>";
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]>|
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.