01-14-2009 09:25 AM
Hello,
I would like to ask if any of NI Graph Control for .Net gives possibility of dragging and moving points on graph by the mouse.
Here is simple example describing what I'm thinking about:
If there is no such functionality, can it be implemented and if it can than in such way?
a.h.
Solved! Go to Solution.
01-15-2009 07:33 AM
Hi xvc
Unfortunatelly, it is not possible to do it in a simple way. There is no direct method for this object to do it. However, the action itself is possible to implement. I was not able to find an example exactly for .NET, but you can see a similar application in LabWindows/CVI here: http://forums.ni.com/ni/board/message?board.id=180&message.id=11767&requireLogin=Fals. In general you should create a cursor, which can be controlled by the user, and the graph should redraw the plot always when the position of the cursor changes. You can find the list of all methods and properties in Measurement Studio Help.
Please let me know, if that works for you.
You can also find this article interesting: http://zone.ni.com/devzone/cda/tut/p/id/2820
PS. Please do not create double posts like this one: http://forums.ni.com/ni/board/message?board.id=232&message.id=8132. It won't speed up the answer, but creates unnecessary data in the forum.
01-15-2009 08:11 AM - edited 01-15-2009 08:16 AM
Thank You very much for answer. I will check it.
At this moment I'm wondering about using annotation to make such functionality, but I don't know how to get x, y coordinates of its caption. I would like to use
AfterDragAnnotationCaption event but there is only xOffset, YOffset in eventarg and I don't know how to convert it to coordinates of plot.
For example if I set some caption position: anntotaion.SetCaptionPosition(1, 3) I would like to get this position (1,3).
p.s. Sorry for this second post, it was my mistake, but I have no idea how to delete posts in this forum...
a.h
01-15-2009 08:16 AM
Hi
I have answered your question regarding getting the annotation position in email, as a reply to your request. In short, using GetAnnotationAttribute, and taking X-value and Y-value attributes should do the job.
01-15-2009 08:46 AM - edited 01-15-2009 08:48 AM
Hello,
Unfortunately in .NET I didn't find GetAnnotationAttribute method, but I think that x-value and y-value are corresponding to position of annotation point, not the caption. I'm looking for position of caption. I suppose that xOffset and yOffset from AnnotationAttributes(LabWindows) and form AfterDragXYAnnotationCaptionEventArgs(.NET) do the job but it my case it returns some strange values and I have no idea how to convert it to coordinates of the graph.
a.h
ps. I reply here because I have no mail to you, only the techsupport@ni.com ...
01-15-2009 09:56 AM
Hello,
It sounds like you may be heading in a different direction, but I thought I would offer my 2 cents. One possibility would be to update the point in the data array based on the mouse position in the MouseMove callback, and then replot the data. While it may not fully meet all your needs, a simple example of how to do this is below. Hopefully it can be of some use to you.
public partial class Form1 : Form
{
private Double[] xData = { 2, 4, 7, 8, 5, 4, 2 };
private Double[] yData = { 5, 8, 9, 6, 3, 2, 5 };
private int pointIndex;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
scatterGraph1.PlotXY(xData, yData);
}
private void scatterGraph1_MouseDown(object sender, MouseEventArgs e)
{
double xPoint;
double yPoint;
scatterPlot1.InverseMapDataPoint(scatterGraph1.Bounds, e.Location, out xPoint, out yPoint);
// This XYCursor is transparent in color, and it's
// SnapMode is set to NearestPoint
xyCursor1.MoveCursor(xPoint, yPoint);
Cursor.Current = Cursors.Hand;
}
private void scatterGraph1_AfterMoveCursor(object sender, NationalInstruments.UI.AfterMoveXYCursorEventArgs e)
{
pointIndex = xyCursor1.GetCurrentIndex();
}
private void scatterGraph1_MouseMove(object sender, MouseEventArgs e)
{
double xPoint;
double yPoint;
if (Cursor.Current == Cursors.Hand)
{
scatterPlot1.InverseMapDataPoint(scatterGraph1.Bounds, e.Location, out xPoint, out yPoint);
xData[pointIndex] = xPoint;
yData[pointIndex] = yPoint;
scatterGraph1.PlotXY(xData, yData);
}
}
private void scatterGraph1_MouseUp(object sender, MouseEventArgs e)
{
Cursor.Current = Cursors.Default;
}
}
NickB
National Instruments
01-16-2009 08:24 AM