Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in graph with time axis in WPF

Solved!
Go to solution

i'm new  to use measurement studio.

 

 

i used the rangeadjusters in examples, followed some posts in this discussion board ,and put some my own codes trying to make the graph having a time axis.

but now i'm stuck in a problem. here it's .

 

there is the coeds i added;

 

In xmal part:

 

<ni:Graph x:Name="graph" Margin="5,5,89,5">
   <ni:Graph.Plots>    

   

       <!-- To prevent the 😛 show up, i put space between the ':' and 'P'  -->


       <ni: Plot Name="p1" Tag="line1" Label="das">
           <ni:LinePlotRenderer Stroke="Red" StrokeDashCap="Round"/>
      </ni: Plot>
   <ni: Plot Name="p2" Label="ddda">
           <ni:LinePlotRenderer Stroke="Black"/>
    </ni: Plot>
    <ni: Plot Name="p3" Label="Xdda">
             <ni:LinePlotRenderer Stroke="BlueViolet" StrokeDashArray="1 4 1"/>
     </ni: Plot>

  </ni:Graph.Plots>
  <ni:Graph.Axes >
        <ni:AxisDateTime Orientation="Horizontal" >
            <ni:AxisDateTime.MajorDivisions>
                  <ni:RangeLabeledDivisions LabelPresenter="yy-mm-dd hh:mm:ss" />
             </ni:AxisDateTime.MajorDivisions>
       </ni:AxisDateTime>
  </ni: Graph.Axes>
</ni: Graph>

 

the C# codes putted in  OnPlotDataClicked

 

AnalogWaveform<double>[] waves ;
double[ , ] plotData = new double[3 ,DataCount];

for (int j = 0; j < 3; j++)
{

  for (int i = 0; i < DataCount; ++i)
  {
     double value = 1.2 * random.NextDouble() * Math.Sin(i * Math.PI * Math.PI / DataCount);

      plotData[j,i] = value;
   }
}

waves = AnalogWaveform<double>.FromArray2D(plotData);

for (int k = 0; k < 3; k++)
{

   WaveformTiming timing = WaveformTiming.CreateWithRegularInterval(new TimeSpan(0, 0, 0, 30), DateTime.Now);

   waves[k].Timing = timing;

}

graph.DataSource = waves;

 

the result

t1.jpg

 

 

but the result is not i want, the time axis show the wrong date at all. how to make it right. wait for your hlep, thanks a lot

 

 

 

0 Kudos
Message 1 of 7
(8,153 Views)
Solution
Accepted by defygravity

By default, the PreferIndexData property is set to true for the Graph control. This means the graph uses the index values of the waveform instead of the timing information, and then coerces index values to DateTime to match the axis (so index 0 coerces to "1 January 0001").


We have a task to improve this behavior, but for now if you set PreferIndexData to false, the graph will use the time information and update the axis range to match that of the waveform.

~ Paul H
0 Kudos
Message 2 of 7
(8,139 Views)

Paul ,Thank you very much.

 

followed your lead,i add the"PreferIndexData" property in xaml and setted it as "false",which is like this

 

<ni:Graph x:Name="graph" Margin="5,5,89,5"  RenderMode="Vector"  PreferIndexData="False"   >

 

and debug it. when it run at this line

 

' graph.DataSource = wave'  

 

it throw me a fault, which said "Unable to cast 'NationalInstruments.DataInfrastructure.Buffer`1[System.Int32]'  object to 'NationalInstruments.DataInfrastructure.Buffer`1[NationalInstruments.DateTime]'  object .

 

fristly, thought it caused by not to set the axis range.so i add codes below before ' graph.DataSource = wave'  

 

"Range<DateTime> ran = new Range<DateTime>(waves[0].Timing.StartTime, waves[0].Timing.StartTime.Add(waves[0].Timing.SampleInterval.Multiply(waves[0].SampleCount)));

 

((AxisDateTime )graph.Axes[0]).Range = ran;"

 

but,the program give me the same wrong tips.  how to fix it? please give me a hand, thanks

 

P.S.  the measurement studio version i use is 12.0.0.318,  VS version is 2010 SP1, 

and .net farmework is  4 and 4 with update(kb2478063) both farmework versions  i  have tried,
target platform " any cpu"

0 Kudos
Message 3 of 7
(8,130 Views)

Below is the code I modified in the Range Adjusters example to match what you posted earlier. Testing in Measurement Studio 2013, I could not get the exception you described. Are you doing anything else in your project? And please post the full exception and stack trace, which will help narrow down the issue.


    XAML
    <ni:Graph x:Name="graph" Margin="5,5,89,5" PreferIndexData="False">
        <ni:Graph.Plots>
            <ni:Plot Name="p1" Tag="line1" Label="das">
                <ni:LinePlotRenderer Stroke="Red" StrokeDashCap="Round"/>
            </ni:Plot>
            <ni:Plot Name="p2" Label="ddda">
                <ni:LinePlotRenderer Stroke="Black"/>
            </ni:Plot>
            <ni:Plot Name="p3" Label="Xdda">
                <ni:LinePlotRenderer Stroke="BlueViolet" StrokeDashArray="1 4 1"/>
            </ni:Plot>
        </ni:Graph.Plots>
        <ni:Graph.Axes >
            <ni:AxisDateTime Orientation="Horizontal" >
                <ni:AxisDateTime.MajorDivisions>
                    <ni:RangeLabeledDivisions LabelPresenter="yy-mm-dd hh:mm:ss" />
                </ni:AxisDateTime.MajorDivisions>
            </ni:AxisDateTime>
        </ni:Graph.Axes>
    </ni:Graph>
    <ni:Legend Width="84" HorizontalAlignment="Right" ItemsSource="{Binding ElementName=graph}" />

    Code
    private void OnPlotDataClicked( object sender, RoutedEventArgs e ) {
        Random random = new Random( );
        double[,] waveData = new double[3, DataCount];
        for( int j = 0; j < 3; ++j )
            for( int i = 0; i < DataCount; ++i )
                waveData[j, i] = 1.2 * random.NextDouble( ) * Math.Sin( i * Math.PI * Math.PI / DataCount );

        var waves = AnalogWaveform<double>.FromArray2D( waveData );
        for( int k = 0; k < 3; ++k )
            waves[k].Timing = WaveformTiming.CreateWithRegularInterval( new TimeSpan( 0, 0, 0, 30 ), DateTime.Now );

        graph.DataSource = waves;
    }

~ Paul H
0 Kudos
Message 4 of 7
(8,117 Views)

Hi.paul.  thank you very much and sorry for my carelessness to take up your time.

 

i do use your code pasted here. there is no fault throwed. so i checked my codes , figure out  i use the array 'plotData' there were 'null'  variables  which cause the problem.

 

 

 

 

P.S

Not like timing tag mismatch with plot data, the reason will be told  exactly. the graph thorw a fault warn me the 'null' variable are not acceptable would be better

 

StackTrace :

 

@ System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext()
@ System.Linq.Buffer`1..ctor(IEnumerable`1 source)
@ System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
@ NationalInstruments.DataInfrastructure.BufferPool.Join[TData](IEnumerable`1 buffers, Unit unit, Func`2 traitFilter)
@ NationalInstruments.Controls.Internal.BufferExtensions.a[a](IList`1 A_0)
@ lambda_method(Closure , IList`1 )
@ NationalInstruments.Controls.Internal.BufferExtensions.JoinBuffers(IList`1 buffers)
@ NationalInstruments.Controls.Internal.DescriptorHelper.MultiSampleImpl`2.DecomposeValues(IBuffer values, Trait decomposeOption)
@ NationalInstruments.Controls.Internal.DecomposeStep.a(IBuffer A_0, List`1 A_1)
@ NationalInstruments.Controls.Internal.DecomposeStep.b[a](IBuffer A_0, a A_1, Func`3 A_2)
@ NationalInstruments.Controls.Internal.DecomposeStep..ctor(Object value, Trait decomposeOption, IDataProcessor dataProcessor)
@ NationalInstruments.Controls.Internal.DefaultPipelineDataProcessor.b(Object A_0)
@ NationalInstruments.Controls.Internal.DefaultPipelineDataProcessor.SplitDataSourceCore(Object dataSource)
@ NationalInstruments.Controls.Primitives.DataProcessorBase.SplitDataSource(Object dataSource)
@ NationalInstruments.Controls.Primitives.DataCollection.SetDataSource(Object newDataSource, DataProcessorBase dataProcessor)
@ NationalInstruments.Controls.Primitives.GraphBase.OnDataSourceChanged()
@ NationalInstruments.Controls.Primitives.GraphBase.a(DependencyObject A_0, DependencyPropertyChangedEventArgs A_1)
@ System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
@ System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
@ System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
@ System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
@ System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
@ System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
@ NationalInstruments.Controls.Primitives.GraphBase.set_DataSource(Object value)
@ NationalInstruments.Examples.RangeAdjusters.MainWindow.OnPlotDataClicked3(Object sender, RoutedEventArgs e) location

 C:\Users\Public\Documents\National Instruments\MStudioVS2010\DotNET\Examples\WPF\Standard\RangeAdjusters\cs\MainWindow.xaml.cs: Line 78

0 Kudos
Message 5 of 7
(8,090 Views)

What data did you send to the graph that caused it to crash, and how was the graph configured?

~ Paul H
0 Kudos
Message 6 of 7
(8,083 Views)

Just wanted to let you know that PreferIndexData in the Measurement Studio 2015 release can now automatically determine the value based on your data and graph configuration.

~ Paul H
0 Kudos
Message 7 of 7
(6,309 Views)