NDataPointDragTool with NAxisValueSnapper


https://www.nevron.com/Forum/Topic13049.aspx
Print Topic | Close Window

By cho seongho - 4 Years Ago
Hi.

I want to move datapoint aligned with MinorTick.
Can I use NDataPointDragTool with NAxisValueSnapper?
By Nevron Support - 4 Years Ago
Hi Cho,
The following code shows how to implement minor tick snapping while dragging a point a with the mouse:

class NCustomDataPointDragTool : NDataPointDragTool
{
protected override NDataPointXYZValue GetDataPointXYZValue(NVector3DF pointModel)
{
NDataPointXYZValue value = base.GetDataPointXYZValue(pointModel);

NChart chart = GetActiveChart();

value.X = chart.Axis(StandardAxis.PrimaryX).SnapValueToNearestMinorTick(value.X);

return value;
}
}

public Form1()
{
InitializeComponent();

NChart chart = nChartControl1.Charts[0];

NLinearScaleConfigurator scaleX = new NLinearScaleConfigurator();
scaleX.MinorTickCount = 2;
chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX;

NPointSeries point = new NPointSeries();
point.UseXValues = true;

point.Values.Add(10);
point.XValues.Add(10);

point.Values.Add(20);
point.XValues.Add(20);

point.Values.Add(30);
point.XValues.Add(30);

chart.Series.Add(point);

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

NCustomDataPointDragTool dragTool = new NCustomDataPointDragTool();
dragTool.DataPointChanged += DragTool_DataPointChanged;
nChartControl1.Controller.Tools.Add(dragTool);
}

Please note that for this to compile you need to download the latest version of .NET Vision as the GetDataPointXYZValue method was previously hidden (obfuscated).

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