Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

wpf scatter graph and intesity graph

Hi,

I'm trying to plot a scatter graph with a list<> containing frequency and amplitude values. I know WPF doesn't take plot methods, i tried setting datasource =  list but it didnt work either. Below is the code i'm using, i have a class called Ucs1 which corresponds to the location of the node i get the data from. I'm going through a datagrid that displays data from a postgreSQL server and gathering the points that belong to the node then adding them to the list<>.

Any help is appreciated..

 

double TOLERANCE = 0.01;
            List<Ucs1> lstUcs1 = new List<Ucs1>();
            foreach (DataRowView row in DataGrid1.ItemsSource)
            {
                string rowValue = row["latitude"].ToString();             
                if (Math.Abs(Convert.ToDouble(rowValue) - ucs1.lat) < TOLERANCE)
                {
                    var freq = Convert.ToDouble(row["frequency"].ToString());
                    var amp = Convert.ToDouble(row["maxamplitude"].ToString());
                    var intercept = Convert.ToDateTime(row["firstintercept"].ToString());
                    Ucs1 ucs1Data = new Ucs1(freq, amp, intercept)
                    {
                        Frequency = freq,
                        MaxAmplitude = amp,
                        FirstIntercept = intercept
                    };
                    lstUcs1.Add(ucs1Data);                  
                }
               
            }

 

0 Kudos
Message 1 of 5
(3,808 Views)

The basic types supported by the WPF graph are described in the How to: Plot and Chart help topic. Custom data types are also supported through the (see this answer to another question for a simple example).

 

The custom descriptor will allow your data to represent a single point in the graph. However, since your type contains multiple values, it is not clear to me what result you expect to see in a scatter or intensity graph. Are you trying to plot "amplitude" vs. "frequency"? "intercept" vs. "amplitude"? Or represent "amplitude" with a color at a position defined by "intercept" and "frequency"?

 

If you only want to represent a subset of the items in your data (i.e. have one plot showing "amplitude" and a separate plot showing "frequency"), the simplest approach is probably to translate your values into a separate list of one of the supported data types (e.g. "List<Point>") and adding it to the graph that way. If do you want all values represented as a single point, then a custom descriptor will work.

~ Paul H
0 Kudos
Message 2 of 5
(3,752 Views)

Hi Paul,

Thank you very much for your answer. What I'm trying to accomplish is to plot the values of amplitude( Y axis) by frequency(X axis) onto a scatter graph, those values are contained in a List<>. finally as you mention represent amplitude with a color at a position defined by intercept and frequency on the intensity graph. Those values are contained on a different list<>. When is set the datasource to equal a list containing only one set of values the plot works but not with more than one set of values. So I guess my questions would be how do I get both axis to to represent the values and in the case of intensity, do I need a 2D array for it or would it take a datasource containing 3 set of values. 

Thanks 

0 Kudos
Message 3 of 5
(3,731 Views)

Yes, intensity data can accept a data source containing three values, either through a custom descriptor or using a data type like Point3D.

 

I'm not sure I follow the description of your data source setup for your graph (or graphs). If you could provide a simple example application that demonstrates your scenario, it would be easier for us to give specific answers for your questions. There are several options, but I will say that using a List<Point> for the frequency/amplitude plot and a List<Point3D> for the intercept/frequency/amplitude plot should function as you expect, without any other work.

~ Paul H
0 Kudos
Message 4 of 5
(3,728 Views)

Hi again Paul,

 

Thanks for helping me with me and I'm sorry i haven't been clear enough, I'm new with Measurement Studios and WPF as well, i've been stuck in my application due to the plotting and i certainly apprciate your help very much. I will be looking into the List<point> as you sugested, but i will try to explain my set up a little clearer.

as i said before I have a datagrid that display all the fields collected from my remote sensors. i use a foreach to go troug all the rows in my datagrid and store a particular row value from the "latitude" column.

 

foreach (DataRowView row in MainDg.ItemsSource)
            {
                string rowValue = row["latitude"].ToString();

 

then i compare that latitude value to a known  remote sensonrs latitude and if they match i know those fields belong to what particular node and proceed to store the "frequency" and the "latitude" values.

 

if (Math.Abs(Convert.ToDouble(rowValue) - ucs1.ucs1Lat) < tolerance)
                {
                    var freq = Convert.ToDouble(row["frequency"].ToString());
                    var amp = Convert.ToDouble(row["maxamplitude"].ToString());
                    Ucs1 ucs1Data = new Ucs1(freq, amp)
                    {
                        Frequency = freq,
                        MaxAmplitude = amp                        
                    };

Then i add those values to a List<Class> that would contain all frequency and amplitude values i collected previously.

 

lstUcs1.Add(ucs1Data);
                    ucsfreqs.Add(freq);
                    ucs1amps.Add(amp);

 

As you can see i end up having a list<Ucs1> that has all frequency and amplitude points i needed. Both freq and amp values are of double type. I would like to use this List as my datasource for the graph. I do the same process for the intesity i collect all 3 values frequency, amplitude and firstintercept on a separate List<class>. The rage of frequencies and amplitudes would constanty change based on user parameters. I have a GUI where the user specifies the Start and Stopt frequency with the Start and Stop date, and the program retrives the information fromthe SQL sever and makes it visible on the Datagrid. That's why i gave to gather the data from the datagrid.

 

Thanks


                   

 


               

 

 

0 Kudos
Message 5 of 5
(3,722 Views)