09-04-2012 12:11 AM
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.
When the application starts
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>
Solved! Go to Solution.
09-04-2012 11:01 AM
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>
09-05-2012 04:55 AM
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?
09-05-2012
09:27 AM
- last edited on
03-27-2025
08:07 AM
by
Content Cleaner
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;
}
09-05-2012 06:56 PM
Hi, Mr. Paul H
It works good. Thank you so much.
09-06-2012 08:58 AM
Happy to help 🙂
08-11-2015
10:31 AM
- last edited on
03-27-2025
08:07 AM
by
Content Cleaner
Just wanted to let you know this issue (#369189) was fixed in the Measurement Studio 2015 release.