Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

mysql datasource and plotting multiple trends against dateTime

Visual Studio 2010 pro

Measurement Studio 2010 standard

C# and .NET

 

I have been working on a little test app to see if Measurement Studio is good for what I want to do.

 

Now I have a simple windows form app working with a MySQL database as a datasource. I have used  datasource binding to get data from a MySQL table into a waveformGraph and have done 4 ".PlotY(....), one for each column od data in the table. Good so far.

 

Now I also have a "time_stamp" column in the database of dataType "System.DateTime". Now instead of just having my 1D waveformGraph I would like to add the DateTime on the x-axis.

 

How would I best do this? Would this be easy to do using a ScatterGraph control or?

 

 


0 Kudos
Message 1 of 2
(4,361 Views)

Hello there,

 

 

See the XAxis.MajorDivisions.LabelFormat to DateTime formats that MStudio supports.

Here is the sample code!

 

 this.xAxis1.MajorDivisions.LabelFormat = new NationalInstruments.UI.FormatString(NationalInstruments.UI.FormatStringMode.DateTime, "G");

 

If the timestamps have different values, then typically the data is supplied to the WaveformGraph using AnalogWaveform<double> of irregular time stamps. AnalogWaveform.Samples has the data and AnalogWaveform.Timing has the timing information. In typical use case this data is generated from NI hardwares.

 

Here is how to do it programmatically!

 

            NationalInstruments.AnalogWaveform<double> waveform = new NationalInstruments.AnalogWaveform<double>(100);

            // set your data
            for(int i=0; i<waveform.SampleCount; i++)
            {
                waveform.Samples[0].Value = 0; // <your data here>
            }

            // set timing information
            DateTime[] timeStamps = new DateTime[100]; // set them or get it from database
            for (int i = 0; i < waveform.SampleCount; i++)
            {
                timeStamps[i] = DateTime.Now;
            }
            waveform.Timing = NationalInstruments.WaveformTiming.CreateWithIrregularInterval(timeStamps);

            // plot the waveform
            waveformGraph1.PlotWaveform(waveform);

 

However, if you insist on not using AnalogWaveform, you will have to convert the timestamp in DateTime[] to double[] using the DataConverter type.

See the following code!

NOTE: You will need to use the scatter graph for the following case

 

            DateTime[] timeStamps = new DateTime[100]; // <your timestamp data here>
            double[] xData = NationalInstruments.DataConverter.Convert(timeStamps, typeof(double[])) as double[];
            double[] yData = new double[100]; // <your data here>
            scatterGraph1.PlotXY(xData, yData);

 

Hope this helps!

 

Regards,

Vijet Patankar,

National Instruments.

0 Kudos
Message 2 of 2
(4,360 Views)