Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

incorrect x axis

Solved!
Go to solution

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.

0 Kudos
Message 1 of 15
(5,675 Views)

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,

Daniel Dorroh
National Instruments
0 Kudos
Message 2 of 15
(5,647 Views)

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.

0 Kudos
Message 3 of 15
(5,630 Views)

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,

Daniel Dorroh
National Instruments
0 Kudos
Message 4 of 15
(5,628 Views)

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.

Download All
0 Kudos
Message 5 of 15
(5,597 Views)

To add more details to my problem, I implemented

http://forums.ni.com/t5/Measurement-Studio-for-NET/WPF-graph-display-point-value-on-hover/m-p/243395...

 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.

0 Kudos
Message 6 of 15
(5,546 Views)

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,

Daniel Dorroh
National Instruments
0 Kudos
Message 7 of 15
(5,505 Views)

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.

0 Kudos
Message 8 of 15
(5,490 Views)

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:

WPFGraph1.JPG

 

If switch is false, you see a graph that looks like this:

WPFGraph2.JPG

 

 

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,

Daniel Dorroh
National Instruments
0 Kudos
Message 9 of 15
(5,443 Views)

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.

0 Kudos
Message 10 of 15
(5,422 Views)