Hi Tobias,
You need to dynamically switch the cursor synchronization mode - the problem is that cursors are not hit testable so you need to perform some type of hit testing using logical coordinates. The following example shows how to achieve a chart with two dragable cursors:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
NAxisCursor m_AxisCursor1;
NAxisCursor m_AxisCursor2;
NCartesianChart m_Chart;
bool m_DraggingCursor;
private void Form1_Load(object sender, EventArgs e)
{
m_Chart = (NCartesianChart)nChartControl1.Charts[0];
NBarSeries bar = new NBarSeries();
bar.Values.Add(10);
bar.Values.Add(20);
bar.Values.Add(30);
m_Chart.Series.Add(bar);
NAxis axis = m_Chart.Axis(StandardAxis.PrimaryY);
m_AxisCursor1 = new NAxisCursor();
m_AxisCursor1.Value = 15;
m_AxisCursor1.BeginEndAxis = (int)StandardAxis.PrimaryX;
m_AxisCursor1.SynchronizeOnMouseAction = MouseAction.None;
m_AxisCursor1.StrokeStyle.Width = new NLength(3);
axis.Cursors.Add(m_AxisCursor1);
m_AxisCursor2 = new NAxisCursor();
m_AxisCursor2.Value = 25;
m_AxisCursor2.BeginEndAxis = (int)StandardAxis.PrimaryX;
m_AxisCursor2.SynchronizeOnMouseAction = MouseAction.None;
m_AxisCursor2.StrokeStyle.Width = new NLength(3);
axis.Cursors.Add(m_AxisCursor2);
NDataCursorTool dataCursorTool = new NDataCursorTool();
nChartControl1.Controller.Tools.Add(new NSelectorTool());
nChartControl1.Controller.Tools.Add(dataCursorTool);
nChartControl1.MouseDown += new MouseEventHandler(nChartControl1_MouseDown);
nChartControl1.MouseUp += new MouseEventHandler(nChartControl1_MouseUp);
}
void nChartControl1_MouseUp(object sender, MouseEventArgs e)
{
if (m_DraggingCursor)
{
m_AxisCursor1.SynchronizeOnMouseAction = MouseAction.None;
m_AxisCursor2.SynchronizeOnMouseAction = MouseAction.None;
m_DraggingCursor = false;
nChartControl1.Capture = false;
}
}
void nChartControl1_MouseDown(object sender, MouseEventArgs e)
{
NPointF viewpoint = new NPointF(e.X, e.Y);
if (!m_Chart.PlotArea.Contains(viewpoint))
{
return;
}
NViewToScale1DTransformation tranform = new NViewToScale1DTransformation(nChartControl1.View.Context, m_Chart, (int)StandardAxis.PrimaryY, (int)StandardAxis.PrimaryX);
double value = 0;
tranform.Transform(viewpoint, ref value);
m_AxisCursor1.SynchronizeOnMouseAction = MouseAction.None;
m_AxisCursor2.SynchronizeOnMouseAction = MouseAction.None;
m_DraggingCursor = false;
if (Math.Abs(m_AxisCursor1.Value - value) < 1)
{
m_AxisCursor1.SynchronizeOnMouseAction = MouseAction.Move;
m_DraggingCursor = true;
nChartControl1.Capture = true;
}
if (Math.Abs(m_AxisCursor2.Value - value) < 1)
{
m_AxisCursor2.SynchronizeOnMouseAction = MouseAction.Move;
m_DraggingCursor = true;
nChartControl1.Capture = true;
}
}
}
The only problem with this code is that you need to provide some hot area around the cursor - in the above code this is achieved trough:
if (Math.Abs(m_AxisCursor1.Value - value) < 1)
That is problematic if the range of the Y axis is very small (as it will result in a large hot area) so you need to add some code that actually does that in pixels.
Hope this helps - let us know if you meet any problems.
Best Regards,
Nevron Support Team