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 |