Nevron Forum

How to configure annotations to appear in plot area only

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

By Vladimir Bershadsky - Monday, October 7, 2013

Hi,

1. Tell me please how do I configure annotations to be shown within plot area bounds, or at least to disappear from sight when anchor point is not visible in current page view? You can see my problem in attached picture (Annotation.jpg). I used this code to create annotation:

         NRectangularCallout annotation = new NRectangularCallout();         annotation.Anchor = anchor;         annotation.Text = text;         annotation.AlwaysInsideParent = false;          annotation.ArrowBasePercent = 0F;         annotation.ArrowLength = new NLength(10F, NRelativeUnit.ParentPercentage);          annotation.FillStyle = new NColorFillStyle(Color.FromArgb(255,255,200));         annotation.PositionMode = CalloutPositionMode.AlignToText;         annotation.Orientation = 270F;         annotation.UseAutomaticSize = true;
   chartControl.Panels.Add(annotation);
2. Is it possible to use Offset Tool to drag and move annotations? 
Thank you very much in advance,
Vladimir
 
 
By Nevron Support - Tuesday, October 8, 2013

Hi Vladimir,

1. What is the type of anchor you currently use? If it is a scale point anchor then you can specify that the annotation is not displayed using the Mode property (AxisValueAnchorMode.Clip) otherwise you can override the anchor IsVisible method and return false if the anchor is not visible.

2. No currently we don't have such functionality.

Let us know if you have any questions or meet any problems.

By Vladimir Bershadsky - Tuesday, October 8, 2013

Hi,

1. I use data point anchor (NDataPointAnchor). Can you please explain me how do I override the anchor IsVisible method?

2. It's OK, actually. I have already achieved necessary functionality by building custom DragTool.

Thank you.

Vladimir

By Nevron Support - Wednesday, October 9, 2013

Hi Vladimir,

The following code shows how to override the IsVisible method of the data point achor:

  [Serializable]
  class NMyAnchor : NDataPointAnchor
  {
   /// <summary>
   /// Default constructor
   /// </summary>
   public NMyAnchor()
   {

   }
   /// <summary>
   /// Initializer constructor
   /// </summary>
   /// <param name="chart"></param>
   /// <param name="line"></param>
   /// <param name="series"></param>
   /// <param name="dataPointIndex"></param>
   /// <param name="contentAlignment"></param>
   /// <param name="depthAlignment"></param>
   public NMyAnchor(NSeriesBase series, int dataPointIndex, ContentAlignment contentAlignment, StringAlignment depthAlignment)
    : base(series, dataPointIndex, contentAlignment, depthAlignment)
   {
   }
   /// <summary>
   /// Returns true if the anchor point is visible
   /// </summary>
   /// <returns></returns>
   public override bool IsVisible()
   {
    if (!base.IsVisible())
     return false;

    double xValue;

    NLineSeries line = Series as NLineSeries;
    NChart chart = line.Chart;

    if (line.UseXValues)
    {
     xValue = (double)line.XValues[DataPointIndex];
    }
    else
    {
     xValue = DataPointIndex;     
    }

    double yValue = (double)line.Values[DataPointIndex];

    return chart.Axis(StandardAxis.PrimaryX).Scale.RulerRange.Contains(xValue) &&
      chart.Axis(StandardAxis.PrimaryY).Scale.RulerRange.Contains(yValue);
   }
  }

  private void Form1_Load(object sender, EventArgs e)
  {
   NCartesianChart chart = (NCartesianChart)nChartControl1.Charts[0];
   chart.RangeSelections.Add(new NRangeSelection());

   chart.Axis(StandardAxis.PrimaryX).ScrollBar.Visible = true;
   chart.Axis(StandardAxis.PrimaryY).ScrollBar.Visible = true;

   NLineSeries line = new NLineSeries();
   line.DataLabelStyle.Visible = false;

   for (int i = 0; i < 100; i++)
   {
    line.Values.Add(i);
   }

   chart.Series.Add(line);

   NMyAnchor anchor = new NMyAnchor(line, 50, ContentAlignment.MiddleCenter, StringAlignment.Center);

   NRectangularCallout annotation = new NRectangularCallout();
   annotation.Text = "Annotated Data Point";
   annotation.Anchor = anchor;
   annotation.UseAutomaticSize = true;

   chart.ChildPanels.Add(annotation);

   nChartControl1.Controller.Tools.Add(new NSelectorTool());
   nChartControl1.Controller.Tools.Add(new NAxisScrollTool());
   nChartControl1.Controller.Tools.Add(new NDataZoomTool());
  }

Let us know if you meet any problems.

By Vladimir Bershadsky - Thursday, October 10, 2013

Thank you very much! This is exactly what I needed.

Best regards,

Vladimir