02-14-2016 03:40 AM
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);
Solved! Go to Solution.
02-15-2016 12:32 PM
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.
02-15-2016 12:34 PM - edited 02-15-2016 12:35 PM
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.!
02-16-2016 02:27 AM
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.
02-16-2016 02:33 AM
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
02-16-2016 09:58 AM
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
.
02-17-2016 02:11 AM - edited 02-17-2016 02:12 AM
I download your project and check this.
You can see in the following screen shoot that it is happening also in your project :
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.
02-17-2016 09:52 AM
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?
02-23-2016 03:22 AM
The problem was that I used Measurement Studio 2010.
When I change it to 2015 , it solved.