Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

CrosshairLength

Solved!
Go to solution

Hi

I'm using a scattergraph in VB.Net with a noisy XY dataset that has a guassian(ish) peak in it, I want to draw an XYCursor with the Xposition at the max of this peak and the Y at the Half max value for the Y data - this is easy.

However I want to set the length of the horizontal crosshair to be the width of the half max (i.e. showing the FWHM).

I understand that I need to set the HorizontalCrosshairMode = CursorCrosshairMode.Custom however I cannot understand how the HorizontalCrosshairLength relates to my X dataset, the help file is really helpful here!

 

Graeme

0 Kudos
Message 1 of 8
(4,703 Views)

Hi RhombusVS,

 

Could I ask what programs you are using to write this?

 

I found this article which may help: http://zone.ni.com/devzone/cda/tut/p/id/2820

 

Let me know if you are still having problems,

 

Kind Regards,

Owen.S
Applications Engineer
National Instruments
0 Kudos
Message 2 of 8
(4,673 Views)

Hi Owen

 

I'm using Vb.NET 2005, I had already found the article you mention but that relates to the old VB6 component works, I did not spot anything which could help me.

 

RhombusVS

0 Kudos
Message 3 of 8
(4,670 Views)

Sorry Owen

 

I just realised you were asking which NI package I was using.

 

I have Measurement Studio 8.1.2 installed with Visual Studio.NET 2005 and .Net Framework 2.05 SP2

 

RhombusVS

0 Kudos
Message 4 of 8
(4,667 Views)

Hi RhombusVS,

 

Could you explain the problem a little more? I can see in the help files what you were talking about "This property value has an effect only if CursorCrosshairMode is set to Custom. " and this property "HorizontalCrosshairLength" can be used to set the length of the horizontal crosshair. What do you mean you don't understand the way it relates to your X dataset?

 

Kind Regards,

Owen.S
Applications Engineer
National Instruments
0 Kudos
Message 5 of 8
(4,652 Views)

Hi Owen

 

consider this XY data set

 

x()=[0,10,20,30,40,50,60,70,80,90]

y()=[0,1,5,5,6,5,5,1,1,0]

 

I am trying to display the full width half maximum (FWHM) of this data set using an XYCursor on a scattergraph.

 

I plot the data on a scattergraph.

I also have an XYCursor on the graph, I set the Xposition=4 (the centre of the peak) and the Yposition=3 (half the max value in Y)

What I want to do is set the Horizontal Crosshair Length =50 of my X units, which is the width of the peak at Y=3.

 

However the Horizontal Crosshair Length property does not say what its units are and I have not been able to reverse engineer them.

 

Does this help explain what I'm trying to do?

 

Graeme

 

0 Kudos
Message 6 of 8
(4,646 Views)

Hey Graeme - 

 

The units are basically in pixels.  Here's one way you could go about calculating the width you're interested in.  The code has been simplified to deal with your example data set, and statically chooses the cursor location:

 

public partial class Form1 : Form
{
  double[] xData = new double[] { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90 };
  double[] yData = new double[] { 0, 1,  5,  5,  6,  5,  5,  1,  1,  0  };
  public Form1()
  {
    InitializeComponent();
    scatterGraph1.PlotXY(xData, yData);
    PositionCursor();
  }
  private void PositionCursor ()
  {
    xyCursor1.XPosition = 40;
    xyCursor1.YPosition = 3;
    xyCursor1.HorizontalCrosshairMode = NationalInstruments.UI.CursorCrosshairMode.Custom;
    // give your desired width in data units
    xyCursor1.HorizontalCrosshairLength = MapToClientCoordinates(10f);
  }
  private float MapToClientCoordinates(float dataWidth)
  {
    Rectangle bounds = scatterPlot1.GetBounds();
    // don't forget to subtract off the "left" position of the plot bounds...
    return scatterPlot1.MapDataPoint(bounds, dataWidth, 0).X - bounds.X;
  }
}

 

NickB01-15, 13_44_35.png 

Let me know if this isn't what you were looking for. 

 

NickB

National Instruments 

Message Edited by nickb on 01-15-2010 01:50 PM
Message 7 of 8
(4,637 Views)
Solution
Accepted by topic author RhombusVS

Thanks Nick

 

Your example did not do exactly what I needed but by clarifying that the units are pixels, I have now been able the to use the bounds of the plot area and scale them by my xdata to allow me to set my cursor width to what I need

 

Graeme

0 Kudos
Message 8 of 8
(4,608 Views)