08-03-2015 11:17 AM
I am having a problem with the measurement studio scatter graph. The x-axis sometimes doesn't show the right scale until I change the size of the window. This problem was present in measurement studio 2013 but it seems it is now much worse in the 2015 version. Please is anyone having similar issues and is there a workaround for this?
Thanks.
Solved! Go to Solution.
08-03-2015 01:53 PM
Can you tell us more about what actions your application performs that should cause the scale to update? Which Measurement Studio controls are you using (Windows Forms, WPF, WebForms)?
Please post any relevant snippets of code that will help us understand the behavior you are reporting.
Thanks,
08-03-2015 02:44 PM
Hi Daniel,
Thank you for your fast response. This happens whenever I clear the data/plots on the graph and add new data/plots. It doesn't matter if the original data is the same as the new one, the axis can be off by factors ranging from 10 - 1000 for logarithm scale and 2 - 10 for linear scale. The axis immediately shows the right value if I resize the window.
I am using the graph as part of a user control so it is difficult sending the full code. I am ready to show you via teamviewer if you are available.
Thanks.
08-03-2015 02:56 PM
Can you give us a snippet of code representing the update cycle you just described? What properties are you modifying / methods are you calling to clear the graph of plots and subsequently add new plots?
Thanks,
08-03-2015 06:20 PM - edited 08-03-2015 06:47 PM
I usually update the graph as follows:
//clear plots and data
try
{
niGraph.Data.Clear();
niGraph.Plots.Clear();
}
catch
{
}
//add new data and plot
Point[] data = new Point[xValues.Length];
for (int i = 0; i < xValues.Length; i++)
{
data[i] = new Point(xValues[i], yValues[i]);
}
Plot plt = new Plot(name);
niGraph.Plots.Add(plt);
niGraph.Data[niGraph.Plots.Count - 1] = data;
I am attaching two screenshots of the plot before and after I resize the windows without any change in plot/data. I have just noticed that the y-axis also behave in the same way. Thank you.
08-04-2015 06:06 PM
To add more details to my problem, I implemented
to display the value off points near the cursor in a tooltip. While the axis is incorrect, the correct values are always displayed by the tooltip.
Please is there a function I can call on the graph to force the axis to refresh the label (niGraph.Refresh() and niGraph,InvalidateVisuals() are not working).
Thank you.
08-05-2015 02:42 PM
Hi falopsy,
Thanks for providing a snippet for us to look at. I think you can avoid this problem by using the graph's DataSource property for assigning data to the graph rather than manually creating a new plot object. I have attached an example where you can switch between plotting different sets of data to the same graph. To modify the snippet you posted, I would recommend something like the following:
Point[] data = new Point[xValues.Length];
for (int i = 0; i < xValues.Length; i++)
{
data[i] = new Point(xValues[i], yValues[i]);
}
niGraph.DataSource = data;
You should not have to manually clear the data or the plots before assigning the DataSource. For more information on plotting and charting with the Measurement Studio WPF graph, please see: http://zone.ni.com/reference/en-XX/help/372636F-01/mstudiowebhelp/html/wpfgraphplotting/ .
Please let me know if this does not improve the behavior for you.
Thanks,
08-05-2015 03:53 PM
I understand but we plot a lot of graphs in our applications and I have made the user control for the data. Sometimes in the dynamic data, I need to clear the other plots and put new ones on it.
This issue still occur the first time I am plotting the graphs. Is there another way of solving the issue? Thank you.
08-06-2015 04:54 PM
Hi, falopsy
Setting the data in the graph should be as simple as:
if (switch) { niGraph.DataSource = new double[] { 1, 2, 3, 4, 5, 4, 3, 2, 1 }; } else { niGraph.DataSource = new Point[,] { { new Point(1, 1), new Point(2, 2), new Point(3, 3), new Point(4, 4), new Point(5, 5) }, { new Point(1, 5), new Point(2, 6), new Point(3, 5), new Point(4, -3), new Point(5, -2) } }; }
If switch is true, you see a graph that looks like this:
If switch is false, you see a graph that looks like this:
The Measurement Studio WPF graph adapts to the data source provided to its DataSource property. To clear data and replot, you can just set the DataSource to a new data source.
If this will not work for you, can you explain a bit more about why?
Thanks,
08-06-2015 06:39 PM - edited 08-06-2015 06:57 PM
Hi Daniel,
This will not really work for my system. The reason is because I don't plot all the data at the same time, the user control is supposed to allow the application to plot different dynamic data. Let me give you an example, I can plot one graph now and maybe after some time add another plot to the graph. The DataSource property will not allow you to plot on top of of an existing plot whereas with the Data property I can just add another array to the Data (I have just tried to do this). The only way to do this with the DataSource property is to keep a record of all data plotted which I am reluctant to do since I am not sure the graph will not behave in the same way.
I may just roll back to measurement studio 2013 as the problem is not this bad in that version.