Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

WPF Graph: AllPlots collection not contain scales in second time.

Solved!
Go to solution

Hello,

 

I'm using in NI WPF graph, and I'm binding it through datasource property.

 

I have two axes in XAML which represent the scales.

 

When button is pressed I create random data (shown in the code below).

 

But, when I deletes all data and adds data to places in the list that already been added in the past (for example: if I added 3 data in the past and now I will add only 2 or 3), then the plots that are created in the variable AllPlots not get scales except the first (never erased) and it destroys me some things such as zoom.

 

 

List<double> newdata = new List<double>();
Random r = new Random();
for (int i = 0; i < 6000; i++)
{
   newdata.Add(r.Next(-20, 45));
}
Data.Add(newdata);

 

0 Kudos
Message 1 of 9
(5,201 Views)

From your description, it sounds like you add some data to a graph, change scale ranges (e.g. by zooming in), then change the data (which modifies the ranges).


The range behavior is controlled by the Adjuster on the scales, which is set to FitLoosely by default (and by the AdjustHorizontalScale and AdjustVerticalScale properties on the plots). If you change the Adjuster on your scales to None, then the range will only change if you modify it directly.


Also regarding AllPlots, this collection will contain automatically generated plots to match the data you send to the graph. If you want this collection to remain stable even as data is added and removed, you can declare your own plots in the Plots collection.

~ Paul H
0 Kudos
Message 2 of 9
(5,174 Views)

Hi hodaya273,

 

I think that we would need more information to be able to help.  Is there any chance you can post your code so that I can see what is happening?

 

Regards,

G-IV

 

I take it back, I just saw that Paul H. helped out!  Thanks, Paul H.!

0 Kudos
Message 3 of 9
(5,172 Views)

My axes is look like this : 

 

 

XAxis:
  <ni:AxisDouble Adjuster="None"  Orientation="Horizontal" Range="{Binding RangeX, Mode=TwoWay, Source={StaticResource ViewModel}}" Label="Time(sec)">

YAxis:
<ni:AxisDouble Adjuster="None" Orientation="Vertical" Range="{Binding RangeY, Mode=TwoWay, Source={StaticResource ViewModel}}">

I don't use in plots collection because the datasource already genarate the data, in the first time it is work.

 

I just dont undarstand why in the second time the generated data is without scales.

0 Kudos
Message 4 of 9
(5,150 Views)

A few more information about my code:

 

 

I already posted the axes.

 

My DataSource is binding to data property in the model.

 

private ObservableCollection<List<double>> data = new ObservableCollection<List<double>>();
public ObservableCollection<List<double>> Data
{
get { return data; }
set { data = value; }
}

 

I already posted the code that add new data when I click on some button.

 

In addition, I have a button that cleans the graph, when I click on it the following code is activated:

 

Data.Clear();
RangeX = new Range<double>(0, 10);
RangeY = new Range<double>(-40, 40);

 For example: if I put 3 data in first time, in the second time the 2,3 data will be without scales and only if I add a 4th data the all data will get scales

 

0 Kudos
Message 5 of 9
(5,149 Views)

Thanks for the new example code. I have updated and attached the project I used, but I cannot reproduce the problem: after the initial data population, the graph always reports two scales for every plot in AllPlots.

~ Paul H
0 Kudos
Message 6 of 9
(5,136 Views)

I download your project and check this.

 

You can see in the following screen shoot that it is happening also in your project : 

AllPlotsScalesPic.PNG

 

In the first time I added 4 plots, and all of them get scales.

 

In the second time (after clear) when I added 4 plots just the first get scales (it never deleted), and just when I add the 5th plot (new one) all of them get scales.

0 Kudos
Message 7 of 9
(5,122 Views)
Solution
Accepted by topic author hodaya273

Hmm, a very strange problem. Unfortunately, I can't reproduce that behavior at all: I always see "2" for every plot, before clear or after.

 

I assume you ran the example as-is in a new project, without any other changes to match your real application? And are you using the latest version, Measurement Studio 2015?

~ Paul H
0 Kudos
Message 8 of 9
(5,112 Views)

The problem was that I used Measurement Studio 2010.

When I change it to 2015 , it solved.

0 Kudos
Message 9 of 9
(5,026 Views)