Hi Enjoyear,
Yes you can easily achieve const line drag behaviour by intercepting the mouse down, move and up events - for example:
private void Form1_Load(object sender, EventArgs e)
{
NCartesianChart chart = (NCartesianChart)nChartControl1.Charts[0];
NBarSeries bar = new NBarSeries();
bar.Values.Add(10);
bar.Values.Add(20);
bar.Values.Add(30);
chart.Series.Add(bar);
NAxisConstLine constLine = new NAxisConstLine();
constLine.Value = 1;
chart.Axis(StandardAxis.PrimaryX).ConstLines.Add(constLine);
nChartControl1.MouseDown += new MouseEventHandler(nChartControl1_MouseDown);
nChartControl1.MouseMove += new MouseEventHandler(nChartControl1_MouseMove);
nChartControl1.MouseUp += new MouseEventHandler(nChartControl1_MouseUp);
}
NAxisConstLine m_DragLine;
void nChartControl1_MouseUp(object sender, MouseEventArgs e)
{
if (m_DragLine != null)
{
m_DragLine = null;
nChartControl1.Capture = false;
nChartControl1.Cursor = Cursors.Default;
}
}
void nChartControl1_MouseMove(object sender, MouseEventArgs e)
{
if (m_DragLine != null)
{
NViewToScale1DTransformation viewToScale = new NViewToScale1DTransformation(nChartControl1.View.Context, nChartControl1.Charts[0], (int)StandardAxis.PrimaryX, (int)StandardAxis.PrimaryY);
double value = 0;
if (viewToScale.Transform(new NPointF(e.X, e.Y), ref value))
{
m_DragLine.Value = value;
nChartControl1.Refresh();
}
}
}
void nChartControl1_MouseDown(object sender, MouseEventArgs e)
{
NHitTestResult result = nChartControl1.HitTest(new Point(e.X, e.Y));
if (result.ChartElement == ChartElement.AxisConstLine)
{
m_DragLine = nChartControl1.Charts[0].Axis(StandardAxis.PrimaryX).ConstLines[0];
nChartControl1.Capture = true;
nChartControl1.Cursor = Cursors.SizeWE;
}
}
The idea is to check on mouse down whether the currently hit object is the const line you added and then to move it around by transforming the mouse coordinate to scale coordinates.
Hope this helps - let us know if you meet any problems...
Best Regards,
Nevron Support Team