Nevron Forum

Const line label outside of the grid?

https://www.nevron.com/Forum/Topic6073.aspx

By Syrhey Karol' - Monday, January 30, 2012

Hi!

Is it possible to draw a const line label outside of the grid? Like in the red square of the attached image.
Or I should use custom painting for that goal.

Best Regards,
Zonder.
By Nevron Support - Wednesday, February 1, 2012

Hi Zonder,

You can offset the label:

constLine.TextAlignment = ContentAlignment.MiddleCenter;
constLine.TextOffset = new NPointL(-40, 0);

The only problem with this approach is that you have to measure the label first in order not to have a hardcoded offset.

Hope this helps - let us know if you meet any problems or have any questions.

By Syrhey Karol' - Wednesday, February 1, 2012

Hi Guys!

Thank you very much for the advice.
But it seems the chart engine draws constant line text at first and only then axis labels.
In this case we can see that axis label overlaps constant line text. You can see it in attach.
Do you know how to avoid it?

Best Regards,
Zonder.
By Nevron Support - Thursday, February 2, 2012

Hi Zonder,

Another approach is to use custom value labels:

   NChart chart = nChartControl1.Charts[0];

   NBarSeries bar = new NBarSeries();
   bar.Values.Add(10);
   bar.Values.Add(20);
   chart.Series.Add(bar);

   NStandardScaleConfigurator scale = chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator as NStandardScaleConfigurator;

   if (scale != null)
   {
    scale.CreateNewLevelForCustomLabels = false;
    scale.CustomLabelFitModes = new LabelFitMode[] { LabelFitMode.RemoveOverlap };

    NCustomValueLabel customLabel = new NCustomValueLabel();
    customLabel.Text = "Some Label";
    customLabel.Value = 15;
    customLabel.Style.ZOrder = 1;
    scale.CustomLabels.Add(customLabel);
   }
In this case auto labels that are overlapping with the custom label will be removed from the scale.

By Syrhey Karol' - Monday, February 6, 2012

Hi Guys!

Thank you very much for the solution!
I’d only add one more scale configure code line:

scale.CreateNewLevelForCustomLabels = false;
scale.CustomLabelFitModes = new LabelFitMode[] { LabelFitMode.RemoveOverlap };
scale.LabelFitModes = new LabelFitMode[] { LabelFitMode.RemoveOverlap };

And it works better if I use 2 or more custom labels.

Best Regards,
Zonder.