Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Change Graph Axis range at run time in measurement studio with C#

Sir,

How can i change the NI Graph control's Y-Axis or X-Axis range at run time??

0 Kudos
Message 1 of 6
(8,237 Views)

Hello Mahesh,

 

MStudio provides APIs to modify the axes at runtime as you want.

Please see WaveformGraph or ScatterGraph.XAxes and YAxes properties.

 

Vijet Patankar,

National Instruments.

0 Kudos
Message 2 of 6
(8,231 Views)

But I am using WPF controls like Graph, Writable Grpah etc..In XAML code, I can see the Range property. But when i want to set the Axis range in the code, I dont see Range property.Is there any way to set Graph or Writable Graph Axis range in the code??

0 Kudos
Message 3 of 6
(8,222 Views)

The Range property belongs to the Axis of the Graph, rather than the Graph itself. Below is an example of how you might set the range of a Graph in the code behind.

 

((AxisDouble)graph1.Axes[0]).Range = new Range<double>(2, 15);

 

National Instruments
Message 4 of 6
(8,205 Views)

The MS 2010 help doesn't tell you how to do this:  in fact, when you discover the x axis Range attribute and you try to set its values directly you discover it's read only and then you're stuck.  I think there's a place in the help file where it tells you to look at "the following example" and there's no example there.

 

Also, the help for the graph indicates you can establish the x axis range as a constructor parameter, but I could find no parameterized constructor for the scatter graph.

 

Is there any way to create a scatter graph dynamically?

 

0 Kudos
Message 5 of 6
(8,199 Views)

Hi Menchar,

 

If you want to create the graph dynamically in C# instead of XAML, you can use code similar to the code below. Could you point me to the help topics that you were referring to with the missing example code and the x axis range suggestion? We are working to improve our WPF function help over the next few releases, but I want to make sure that what is there currently is correct.

 

Graph myGraph = new Graph();
Plot plot1 = new Plot("Plot 1");
myGraph.Plots.Add(plot1);
AxisDouble xAxis = new AxisDouble();
xAxis.Orientation = Orientation.Horizontal;
xAxis.Range = new Range<double>(0, 1000);
AxisDouble yAxis = new AxisDouble();
yAxis.Orientation = Orientation.Vertical;
yAxis.Range = new Range<double>(-10, 10);
myGraph.Axes.Add(xAxis);
myGraph.Axes.Add(yAxis);
myStackPanel.Children.Add(myGraph);

 

National Instruments
0 Kudos
Message 6 of 6
(8,189 Views)