Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

WPF Graph Reset Axes to origin

Solved!
Go to solution

Hi 

 

Is there a way to reset an horizontal axis to the origin (0)?

I already used ResetZoomPan(), but this set only Pan and Zoom to its initial state.

I would like to reset the graph as appears in the first loading.

 

Thanks to everyone for the help.

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

There is nothing in the graph that keeps track of the history of axis values outside of interactions.


If you want to reset the graph to how it appears when data is first loaded, then you can use the ZoomToFit method. If you want to reset the graph to the default range, then you can update the Range property on the axes.

~ Paul H
0 Kudos
Message 2 of 8
(6,763 Views)

Thanks Paul for your suggestion.

 

Can you give me a clue how to reset the Range of a single Axis (lets say the first)?

 

0 Kudos
Message 3 of 8
(6,755 Views)
Solution
Accepted by topic author Maverjk

Assuming your graph is setup similar to the example below:


    <ni:Graph x:Name="graph" ...>
      <ni:Graph.Axes>
        <ni:AxisDouble x:Name="xAxis" Orientation="Horizontal" ... />
      </ni:Graph.Axes>
      ...
    </ni:Graph>


You can set the range using the named axis element:


    xAxis.Range = new Range(0.0, 10.0)


Or by casting the first item in the Axes collection, if it is unnamed:


    ((Axis<double>)graph.Axes[0]).Range = new Range(0.0, 10.0)

~ Paul H
0 Kudos
Message 4 of 8
(6,749 Views)

That was my final solution:

 

 

Graph.ResetZoomPan();
((Axis<Int32>)Graph.Axes[0]).Range = new NationalInstruments.Controls.Range<Int32>(0, 5000);

 

 

Thanks for your help.

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

I have tried this many way without success.

 

<ni:AxisDouble x:Name="V2y" Adjuster="FitExactly" LabelVisibility="Hidden" Orientation="Vertical" Range="-2, 2, System.Double" Visibility="Hidden" />

 

V2y.Range = Range(-2.0, 2.0)   result in error,

 

 

Error 1 'Range' is ambiguous, imported from the namespaces or types 'NationalInstruments.Controls, NationalInstruments.UI'. U:\PB\Intelitool\WpfApplication1\WpfApplication1\Page1.xaml.vb 254 25 WpfApplication1

 

I can not remove the ui reference as this is part of a large winform project

 

 

V2y.Range = New NationalInstruments.Controls.Range(-2, 2)  result in error

 

Error 2 Type 'NationalInstruments.Controls.Range' has no constructors. U:\PB\Intelitool\WpfApplication1\WpfApplication1\Page1.xaml.vb 255 25 WpfApplication1

What else should I do?

 

Thanks in advance

 

0 Kudos
Message 6 of 8
(6,355 Views)

You are missing the type arguments on the generic Range<TData> type. You can create a new range in VB using New Range(Of Double)( -2.0, 2.0 ), or by calling Range.Create( -2.0, 2.0 ) on the static Range helper class.

~ Paul H
Message 7 of 8
(6,352 Views)

Hi Paul

 

Thank you the code

 

 

AxisXzz.Range = NationalInstruments.Controls.Range.Create(-2000.0, 2000.0)

 

worked great.

 

Thanks

 

George

 

0 Kudos
Message 8 of 8
(6,349 Views)