Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

FitVisibleExactly of WPF Graph

Solved!
Go to solution

Hello,

I'm checking about WPF Graph of Mesurement Studio 2012.

When I operate in the code shown below, FitVisibleExactly does not seem to be working correctly.

 

graph1.PNG 

When the application starts 

 

graph2.PNG

When I zoom horizontally about 30-59, vartical axis is not fit in visble graph.

Please give me some information on this matter.

 

 

[MainWindow.xaml.cs]

using System;
using System.Windows;

namespace GraphTest
{
  public partial class MainWindow : Window
  {
    public MainWindow()
    {
      InitializeComponent();
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
      Point[] plotData = new Point[180];
      for (int i = 0; i < 180; i++)
      {
        plotData[i] = new Point((double)i,Math.Sin((double)i / 180.0 * Math.PI) );
      }
      graph1.DataSource = plotData;
    }
  }
}

 

[MainWindow.xaml]

<Window x:Class="GraphTest.MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="MainWindow" Height="350" Width="525" xmlns:ni="http://schemas.ni.com/controls/2009/xaml/presentation" Loaded="Window_Loaded">
 <Grid>
   <ni:Graph Name="graph1" DefaultInteraction="ZoomHorizontal" RenderMode="Vector">
     <ni:Graph.Axes>
     <ni:AxisDouble x:Name="xAxis" Orientation="Horizontal" />
     <ni:AxisDouble x:Name="yAxis" Orientation="Vertical" Adjuster="FitVisibleExactly" />
     </ni:Graph.Axes>
   </ni:Graph>
 </Grid>
</Window>

 

0 Kudos
Message 1 of 7
(6,687 Views)

Unfortunately, we did not have time to implement all of the interaction-related features for the Fit Visible adjuster modes for the first release of the graph controls. Currently, the adjuster is only invoked when new data is supplied to the graph, not when an axis is modified.


As a workaround, I've created the attached FitVisibleHelper class. It exposes an attached property that will monitor the horizontal axis on a graph for changes, and call AdjustRange on the vertical axis with the visible Point data. (The helper does make a number of assumptions about how the graph is set up; please modify it to fit your needs.)


    ...
    xmlns:my="clr-namsepace:YourProject"
    ...
    </ni:Graph>
        <ni:Graph.Axes>
          ...
        </ni:Graph.Axes>
        <my:FitVisibleHelper.Monitor>True</my:FitVisibleHelper.Monitor>
    </ni:Graph>

~ Paul H
0 Kudos
Message 2 of 7
(6,681 Views)

Hi, Mr. Paul H

 

Thank you for your quick responce.

However, it is necessary to modify

"foreach (Point[] data in graph.Data)"

to 

"foreach (Buffer <Point> data in graph.Data)"

in order to support multi-plot.

It has worked well.

 

There is another question.

Right clik on Graph works as UndoZoom.

How can I stop this behavior?

 

 

0 Kudos
Message 3 of 7
(6,669 Views)
Solution
Accepted by topic author riku

As you have probably noticed, the right-click Undo behavior is a built-in part of the graph, and is not exposed in the Interactions collection.

 

While there is no property to configure this behavior, you can suppress it by handling the mouse right-click event before the graph. Simply subscribe to the PreviewMouseRightButtonUp event set the Handled property on the event args to true.

 

    <ni:Graph PreviewMouseRightButtonUp="OnGraphPreviewMouseRightButtonUp">
        ...
    </ni:Graph>


    private void OnGraphPreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e) {
        e.Handled = true;
    }

~ Paul H
0 Kudos
Message 4 of 7
(6,667 Views)

Hi, Mr. Paul H

It works good. Thank you so much.

0 Kudos
Message 5 of 7
(6,655 Views)

Happy to help 🙂

~ Paul H
0 Kudos
Message 6 of 7
(6,650 Views)

Just wanted to let you know this issue (#369189) was fixed in the Measurement Studio 2015 release.

~ Paul H
0 Kudos
Message 7 of 7
(4,901 Views)