Profile Picture

Trying to implement a basic Data Cursor Tool

Posted By Randy Kondor 11 Years Ago
Author
Message
Randy Kondor
crazy Posted 11 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 3, Visits: 1
I looked at the code for this over and over and it seems like something is missing but I can not see the difference when comparing your example.

m_VerticalAxisCursor = new NAxisCursor();
m_VerticalAxisCursor.BeginEndAxis = (int)StandardAxis.PrimaryX;
m_VerticalAxisCursor.ValueChanged += new EventHandler(OnValueChanged);
m_VerticalAxisCursor.ValueSnapper = new NAxisRulerClampSnapper();
m_VerticalAxisCursor.SynchronizeOnMouseAction |= MouseAction.Move;

for (int i = 0; i < MainList.Count(); i++)
{
NAxis primaryXAxis = MainList[i].Item1.Axis(StandardAxis.PrimaryX);
primaryXAxis.Cursors.Clear();
primaryXAxis.Cursors.Add(m_VerticalAxisCursor);
}

nChartControl1.Controller.Tools.Clear();
nChartControl1.Controller.Tools.Add(m_DataCursorTool);


The event for the value changed never gets hit. Also when I click the chart plot area it shows a vertical line where I clicked, I don't see where that's coming from.

Nevron Support
Posted 11 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Randy,

"Also when I click the chart plot area it shows a vertical line where I clicked, I don't see where that's coming from."

That's most likely the cursor position being updated (though in that case you should get the value changed event). You also need an active chart in order for the data cursor tool to work properly. The following code snippet shows how to achieve that:

  private void Form1_Load(object sender, EventArgs e)
  {
   NChart chart = nChartControl1.Charts[0];

   NPointSeries point = new NPointSeries();

   for (int i = 0; i < 10; i++)
   {
    point.Values.Add(i);
   }

   chart.Series.Add(point);

   NAxisCursor axisCursor = new NAxisCursor();
   axisCursor.BeginEndAxis = (int)StandardAxis.PrimaryY;
   axisCursor.ValueChanged += new EventHandler(OnValueChanged);
   axisCursor.SynchronizeOnMouseAction = MouseAction.Down;
   chart.Axis(StandardAxis.PrimaryX).Cursors.Add(axisCursor);

   nChartControl1.Controller.Tools.Clear();
   nChartControl1.Controller.Selection.SelectedObjects.Add(chart);
   nChartControl1.Controller.Tools.Add(new NDataCursorTool());
  }

  void OnValueChanged(object sender, EventArgs e)
  {
  
  }

Notice that in the above code the active chart is specfied explicitly using:

 nChartControl1.Controller.Selection.SelectedObjects.Add(chart);

You can also use a selector tool to have a dynamically changing active chart (in case you have multiple charts) in which case the code that configures the controller should look like:

nChartControl1.Controller.Tools.Clear();
nChartControl1.Controller.Tools.Add(new NSelectorTool());
nChartControl1.Controller.Tools.Add(new NDataCursorTool());

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



Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic