Chart / Charts / Label Formatting
In This Topic
    Label Formatting
    In This Topic

    The data point labels and the legend data items can display texts that contain information obtained from the series data. The Format properties of the NSeriesLegendView and NDataLabelStyle classes accept a string that can contain formatting commands (enclosed in the < and > characters) that represent a specific data point or a calculated series value.

    The data series formatting commands are specific for the different series and this topic lists only the common formatting commands. Some series have additional formatting commands like the stock series which adds <open>, <high>, <low>, and <close> formatting commands. The additional formatting commands are described in the topic dedicated to the specific series.

    The valid formatting commands that are present in a format string are dynamically replaced with the corresponding formatted values. Each formatting command has a corresponding formatter object. The only exception is the <label> command which takes the data point Label property value directly.

    The following code demonstrates how to use format strings:

    C#
    Copy Code
    // create a bar series
    NBarSeries bar = new NBarSeries();
    chart.Series.Add(bar);
    bar.DataPoints.Add(new NBarDataPoint(10.0));
    bar.DataPoints.Add(new NBarDataPoint(20.0));
    bar.DataPoints.Add(new NBarDataPoint(30.0));
    NDataLabelStyle dataLabelStyle = new NDataLabelStyle();
    dataLabelStyle.Format = "The value of this data point is <value>";
    bar.DataLabelStyle = dataLabelStyle;
    

    You can control the formatting of the data series values through the formatter objects associated with the NSeries (or derived from it) object. The following table lists the commonly supported format commands and their corresponding formatters:

    Formatting Command Formatter Property Description
    <label> None The label associated with the data point.
    <value> ValueFormatter The value of the data point formatted using the specified ValueFormatter.
    <xvalue> XValueFormatter The x value of the data point formatted using the specified XValueFormatter.
    <zvalue> ZValueFormatter The z value of the data point formatted using the specified ZValueFormatter.
    <total> TotalValueFormatter The value of the data point is formatted using the specified TotalValueFormatter. This formatting command is used only in stacked series (stacked area, bar, or line), and pie series.
    <percent> PercentValueFormatter The value of the data point relative to the total in percentages formatted using the specified PercentValueFormatter. This format string is used only in stacked series (stacked area, bar or line) and pie series.
    <cumulative> CumulativeValueFormatter The cumulative value of the data point is formatted using the specified CumulativeValueFormatter. This format is string used in only stacked series (stacked area, bar or line) and pie series.
    <index> IndexValueFormatter The index of the data point is formatted using the specified IndexValueFormatter.

    The following code shows how to change the formatting applied to data point values:

    C#
    Copy Code
    series.ValueFormatter = new NNumericValueFormatter("0.000");
    

     

    See Also