08-12-2009 02:36 AM
Hello forum,
I have following problem to plot/refresh data in a scattergraph:
In my software I use a timer to receive every 500 ms a new data package from an external hardware. After receiving data I perform some calculations and plot calculated data. Every new data package is plotted in a Scattergraph (x-axis = time, y-axis = amplitude) with PlotXYappend command.
PROBLEM --> Sometimes the data is plotted out of the Scattergraph PlotArea (see in the attached image in the red circle). If this happens, the performance of my software falls-off. As long as you can see these "peaks in the out of PlotArea" the refresh-rate of the Scattergaph takes more than 1 sec (without peaks it normally takes <20 ms). This leads to a confilct with my software timer (500 ms - can´t change this value!).
It does not matter which scaling mode for y-axis is selected. This error appears for Fixed-mode as well for Autoscale-mode.
Does anybody know why this error appears and how can I avoid this?
Iam using Visual Studio 2005 (VB.NET) with NI Measurement Studio 8.5 for VS 2005.
Thanks for help
Robert_R
08-13-2009 04:45 AM
Hello Robert,
does this only happen in your application or can you reproduce it on any graph by providing values that are out of range?
Regards,
08-13-2009 06:02 AM
Hello jtagg,
I haven´t tested this problem in other applications. This Scattergraph is implemented as an Usercontrol in an extra form.
But I found some other relations:
The y-Data array consists of values from about -0.5 to +0.5. The random peaks have values about 10. If I select y-axis Scaling mode Fixed (range -2 to +2) or AutoScaleLoose the data is plotted out of the PlotArea (as described in my question above). If I select Scaling mode = AutoScaleExact this error does not appear!
08-14-2009 03:02 AM
Hi Robert,
I would like to reproduce this on my end. Could you provide a small example program that demonstrates the issue, with exact steps on how to reproduce? Please be as exact as possible, so that I can be sure that I'm doing the same thing you are.
Regards,
08-14-2009 09:27 AM
Hello Joseph,
thanks for your offer to reproduce this error on your end. But my software is to complex to generate a small example (at least not in acceptable time effort). I can just describe you what I did:
In the form load event I dynamically add Scattergraph controls. The number and size of the controls is modifiable. [This automatically leads to an other unanswered problem in this NI-forum http://forums.ni.com/ni/board/message?board.id=232&thread.id=8734 😉 ]
Look at the image in the attachment (three dynamically added Scattergraphs in one form). Every control is added at the bottom of the previous control. Then add plots for every Scattergraph, adjust color and HistoryCount of each plots, configure plot area (color, gridlines, etc.), set x-axis Scaling mode to AutoScaleLoose and y-axis Scaling mode to Fixed (-2 to +2).
The x-data array consists of time values (every 5 ms a new time value). And the y-data array consists of measurement values (range from -0.5 to + 0.5). Accidentally appearing measurement errors generate values of more than ca. 10. In any case these error values are out of the actual y-axis scale.
To temporarily avoid this “draw out of plot area” error I use y-axis Scaling mode = AutoScaleExact. But I would be pleased to use Fixed mode to achieve same scaling in every added Scattergraph and to avoid y-axis range change because of measuremt errors.
Best regards
Robert
08-21-2009 04:46 AM
Hi Robert,
I've tried to reproduce your issue on my end and created a simple form with a Scattergraph. I set it to fixed and generated data that goes beyond the maximum value. I haven't been able to see anything wrong when doing it.
Does this only happen to you when you have several scattergraphs? Could it be that you have overlapping elements that could be causing this slowdown?
Regards,
08-21-2009 10:14 AM
Hi Joseph,
did you generated every 500 ms a new data array with ca. 100 new values and add this data array with PlotXYappend to the Scattergaphs? If I add only one big data array (with e.g. 10000 values) to the scattergraphs, this "overplot-error" does not appear. Only with updated data every 500 ms.
But one thing you mentioned could be a very interesting issue: overlapping of the elements. Because I wanted to reduce the space between PlotArea and Control-Border (described above) I overlapped the elements. Maybe you can see something “suspicious” in the added source-code (I bet on line 56 -> something * 0.95). This Function is realized in the form load event. I hope this is not too cryptic…
' Inputs: Startnumber: a number between 1 - 60 that represents the startgraph ' Stopnumber: a number between 1 - 60 that represents the stopgraph ' HistoryCount: HistoryCount-Value of new generated Scattergraphs Public Sub ArrangeScatterGraphs(ByVal StartNumber As Short, ByVal StopNumber As Short, ByVal HistoryCount As Integer) Dim i As Int32, j As Int16 Dim iHeight As Int32 Dim ctrl As Object Dim GraphCaptionNr As Int16 ' Number of shown Scattergraphs Dim GraphCount As Short = (StopNumber - StartNumber) + 1 ' adjust height of Scattergraphs if at least one Scattergraph is added to form If GraphCount > 0 Then iHeight = (Me.Height - 30) / GraphCount End If ' remove existing controls(scattergraphs) in form GraphList.RemoveAll() For i = 0 To 5 For Each ctrl In Me.Controls If TypeOf (ctrl) Is NationalInstruments.UI.WindowsForms.ScatterGraph Then Me.Controls.Remove(ctrl) End If Next ctrl Next i GraphCaptionNr = StartNumber ' start caption with startgraph number ' loop to add every new scattergraph to form For i = 0 To (GraphCount - 1) GraphList.Add() ' add scattergraphs to list (code see below) ''##### add scattergraph to List############ ' Dim myList As New List(Of NationalInstruments.UI.WindowsForms.ScatterGraph) '- classinternal liste of graphs ' 'procedure to add additional graphs to list 'Public Sub Add() ' Dim Graph As NationalInstruments.UI.WindowsForms.ScatterGraph = New NationalInstruments.UI.WindowsForms.ScatterGraph ' Graph.SelectionColor = Color.Blue ' myList.Add(Graph) ' AddHandler Graph.Pan, AddressOf lGraphPan 'End Sub '####################################################### AddHandler GraphList.Item(GraphList.Count - 1).XAxisRangeChanged, AddressOf xAxisChanged AddHandler GraphList.Item(GraphList.Count - 1).CursorChanged, AddressOf GraphCursorChanged ' add scattergraph and adjustsettings With GraphList.Item(GraphList.Count - 1) Me.Controls.Add(GraphList.Item(GraphList.Count - 1)) ' add scattergraph to form from GraphList .Name = GraphCaptionNr .Top = ((iHeight * i) * 0.95) ' to realize an overlap of the scattergraphs .Left = 0 .Width = Me.Width ' adjust height of each scattergraph If i = (GraphCount - 1) Then ' letzte graph If (GraphCount > 1) Then ' more than one graph .Height = iHeight + 30 Else ' only one graph .Height = Me.Height - frmMain.ssStatus.Height End If ' (GraphCount > 1) Else ' not last graph - a little bit bigger to realize overlap .Height = iHeight * 1.05 End If ' i = (GraphCount - 1) ' border and padding of each added scattergraph Dim SizeArray As System.Drawing.Size = .PlotAreaBounds.Size .Border = .Border.None .Padding = New Padding(0, 0, 0, 0) Dim newMargin As New System.Windows.Forms.Padding newMargin.Top = 0 newMargin.Bottom = 0 .Margin = newMargin .Caption = "#" + Str(GraphCaptionNr) .CaptionBackColor = System.Drawing.Color.LightGreen .CaptionPosition = CaptionPosition.Right GraphCaptionNr += 1 ' alternate PlotArea colors If (i + 1) Mod 2 = 0 Then ' even graph number .PlotAreaColor = System.Drawing.Color.LightGray Else 'odd graph number .PlotAreaColor = System.Drawing.Color.OldLace End If .InteractionModeDefault = GraphDefaultInteractionMode.None .InteractionMode = GraphInteractionModes.DragCursor + GraphInteractionModes.PanX + GraphInteractionModes.ZoomX + GraphInteractionModes.ZoomY ' y-axis ############################################### .YAxes.Add(New NationalInstruments.UI.YAxis) With .YAxes(0) .Caption = "[mm]" .MajorDivisions.GridVisible = True ' y-axis scaling mode with range .Mode = AxisMode.Fixed .Range = New Range(-2, 2) ' alternate gridcolors If (i + 1) Mod 2 = 0 Then ' even graph number .MajorDivisions.GridColor = System.Drawing.Color.OldLace .MinorDivisions.GridColor = System.Drawing.Color.OldLace Else 'odd graph number .MajorDivisions.GridColor = System.Drawing.Color.LightGray .MinorDivisions.GridColor = System.Drawing.Color.LightGray End If .MajorDivisions.GridLineStyle = LineStyle.Dash .MinorDivisions.GridVisible = True .MinorDivisions.GridLineStyle = LineStyle.Dash .Position = YAxisPosition.LeftRight .MinimumWidth = 60 .EndLabelsAlwaysVisible = False End With ' x-axis ############################################### .XAxes.Add(New NationalInstruments.UI.XAxis) With .XAxes(0) ' show axis caption only for last added graph If i = (GraphCount - 1) Then ' last graph .CaptionVisible = True Else ' other graphs without axis caption .CaptionVisible = False .Visible = False End If ' check if i = (GraphCount - 1) '### ' adjust caption and formatstring of x-axis .Caption = "Time [hh:mm:ss]" .MajorDivisions.LabelFormat = New NationalInstruments.UI.FormatString(NationalInstruments.UI.FormatStringMode.DateTime, "HH:mm:ss") .MajorDivisions.GridVisible = True ' alternate gridcolors If (i + 1) Mod 2 = 0 Then ' even graph number .MajorDivisions.GridColor = System.Drawing.Color.OldLace .MinorDivisions.GridColor = System.Drawing.Color.OldLace Else ' odd graph number .MajorDivisions.GridColor = System.Drawing.Color.LightGray .MinorDivisions.GridColor = System.Drawing.Color.LightGray End If .MajorDivisions.GridLineStyle = LineStyle.Dash .MinorDivisions.GridVisible = True .MinorDivisions.GridLineStyle = LineStyle.Dash .Mode = AxisMode.AutoScaleLoose .EndLabelsAlwaysVisible = False End With ' add plots to each scattergraph For j = 0 To 7 .Plots.Add(New NationalInstruments.UI.ScatterPlot) .Plots(j).HistoryCapacity = HistoryCount Next j .Update() End With Next i End Sub ' arrangeScatterGraphs
Thanks a lot for your help
Robert
09-01-2009 09:54 AM
Hi Robert,
I tried what you said, generating data every 500ms...on my machine it works fine.
Could you try to not make the controls overlap and then see the result? Does that fix the problem?
Regards,