Scales / Labels / Custom Labels
In This Topic
    Custom Labels
    In This Topic

    Custom labels are used to input additional text information on the scale, that describes a value or a range of values. Custom labels can be added on any scale.

    This is done by adding instances of the NCustomValueLabel and NCustomRangleLabel classes to the CustomLabels collection of the scale. The following pictures show two charts with custom value and range labels introduced to the Y and X axis respectively:

    Chart with Custom Value Label and Reference Line Chart with Custom Range Labels

     

     Adding Custom Value Labels

    The following code will add a custom value label to the chart Y axis:

    C#
    Copy Code
    NCustomValueLabel valueLabel = new NCustomValueLabel(230, "Target");
    scale.CustomLabels.Add(valueLabel);
    

    When you add the custom value label it will be created in a separate scale level. In certain cases however you may wish this label to be positioned alongside the labels generated by the scale. This is done by setting the CreateNewLevelForCustomLabels property to false:

    C#
    Copy Code
    NCustomValueLabel valueLabel = new NCustomValueLabel(250, "Target");
    // give higher priority to this label
    valueLabel.LabelStyle.ZOrder = 1;
    scale.CustomLabels.Add(valueLabel);
    // tell the axis to remove labels that overlap with the custom label
    scale.CustomLabelOverlapResolveLayouts = new NDomArray<ENLevelLabelsLayout>(new ENLevelLabelsLayout[] { ENLevelLabelsLayout.RemoveOverlap });
    scale.CreateNewLevelForCustomLabels = false;
    

    Note that the above code also changes the custom labels layouts. This is required when you want to hide the labels that overlap with the custom label. The following pictures show two scales - the first one with a custom label in a separate level and the second one showing a custom label merged with the automatic labels:

    Custom label in a separate
    scale level
    Custom label merged with the
    automatically generated labels

     

     Adding Custom Range Labels

    Similarly to value labels you add custom range labels by adding an instance of the NCustomRangeLabel class to the CustomLabels collection. The following code shows how to add a custom range label:

    C#
    Copy Code
    NCustomRangeLabel rangeLabel = new NCustomRangeLabel();
    rangeLabel.Text = "Target";
    rangeLabel.LabelStyle.Offset = 10;
    rangeLabel.Range = new NRange(20, 60);
    scale.CustomLabels.Add(rangeLabel);
    

    This code produces the following result provided that you apply it to an already configured chart: