Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

WaveformGraph - Choosing X Axes?

Solved!
Go to solution

This is most likely very simple, but I haven't found a way to do it.  In the designer I've gone into a WaveformGraph's properties and added multiple X axis types to the X axis collection.  Now, what I can't figure out is how can I choose which member of the collection to use programatically?  I'm assuming there must be a way to do this?

 

Thanks,

Randy

 

0 Kudos
Message 1 of 5
(4,235 Views)

Hello Randy,

 

I assume that by 'choose', you mean you want to associate a plot with one of your new X axes.  There are a couple ways you can do this programmatically, with a couple of them shown below:

 

            XAxis newAxis1 = new XAxis();
     XAxis newAxis2 = new XAxis();

     waveformPlot1.XAxis = newAxis1;
     WaveformPlot newPlot1 = new WaveformPlot(newAxis1, yAxis1);
     WaveformPlot newPlot2 = new WaveformPlot(newAxis2, yAxis1);

     waveformGraph1.XAxes.Add(newAxis1);
     waveformGraph1.XAxes.Add(newAxis2);
     waveformGraph1.Plots.Add(newPlot1);
     waveformGraph1.Plots.Add(newPlot2);

 

Basically, when you add axes through the graph through the designer, it adds these axes to either the XAxes or YAxes collections of the WaveFormGraph.  Please let me know if this doesn't address your question, or if there is anything else I can help clarify.

 

NickB

National Instruments 

0 Kudos
Message 2 of 5
(4,222 Views)

Thanks for the reply Nick.  Sorry for being dense but I'm not following what you're doing.  You seem to be adding axes but I've already done that in the designer.  Maybe if we work with the real names I'm using I'll understand what you're trying to say.

 

In my main form I have a WaveformGraph named VoltageGraph.  I opened up the Properties window for VoltageGraph and clicked on the XAxes property which opened up the XAxis Collection Editor.  I created two Members in the collection, one named XAxisVoltage60 (index 0) and one named XAxisVoltage50 (index 1).  The line of code that I use to plot my data is:

 

VoltageGraph.PlotY(VoltageArray)

 

where VoltageArray is an array containing my data.  This works fine, but what I'd like to be able to do is sometimes plot it using XAxisVoltage60 for the x axis and other times use XAxisVoltage50, and be able to choose programatically.

 

Thanks,

Randy

 

0 Kudos
Message 3 of 5
(4,211 Views)
Solution
Accepted by topic author RCBrust

Got it!  What I was missing was that the axes are chosen under the WaveformPlot, not the WaveformGraph.  For example, since VoltageGraph contains WaveformPlot1, I use either

 

WaveFormPlot1.XAxis = XAxisVoltage60

 

or

 

WaveFormPlot1.XAxis = XAxisVoltage50

 

before I plot.  Thanks for your help Nick.

 

Randy

 

0 Kudos
Message 4 of 5
(4,209 Views)

Hello Randy,

 

I'm sorry my example was not a little more clear.  In hindsight, I should have definitely given more context to my code.  Basically, I was just trying to show two of the methods by which you can associate a plot with an axis, and the relationship of the axis with the waveform graph.  

 

When you add axes to the graph through the designer, or programmatically with a piece of code like:

 

waveformGraph1.XAxes.Add(newAxis1);

 

the Axis object is added to the WaveformGraph's Axes collection.  Once you have multiple axes associated with the waveform graph, you then have the option to associate each of your plots with a specific axis, as you have seen how to do.  In addition to the way you found, you can also associate a plot with an axis when you create the plot through one of the overloads on the WaveformPlot constructor, as shown:

 

 WaveformPlot newPlot2 = new WaveformPlot(newAxis2, yAxis1);

 

However, this was maybe a little more information than you were asking for, as it looks like you only have one plot object (WaveFormPlot1).   In this case, what you are doing is exactly what we would recommend.  Please let me know if anything remains a little bit hazy.


NickB

National Instruments 

Message Edited by nickb on 12-05-2008 10:47 AM
0 Kudos
Message 5 of 5
(4,187 Views)