Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Scattergraph crash when programmatically updating y-axis scale beyond a certain range

Solved!
Go to solution

I have a recurring issue that I'm stuck on involving the scattergraph control. I set my scattergraph to a fixed scale from 0-25 on the form loading. When the graph is being updated I check to see if the y-value exceeds the y axis scale. If and when it does I update the fixed scale to range from 0 to the previous maximum range plus 25. So if it exceeded 0-25 range, it would jump to 0-50, if it exceeded 0-50, it would jump to 0-75. The issue I am having though is after the 0-75 range when it tries to change the scaling to 0-100, the graph crashes and turns to a red x. I have no idea why it is doing it at this point, so any help is appreciated. Here is my code for updating the graph:

 

 yAxisMax = YAxis1.Range.Maximum
        If val1 > yAxisMax Or val2 > yAxisMax Then
            ScatterGraph1.YAxes(0).Range = New NationalInstruments.UI.Range(0, yAxisMax + 25)
            ScatterGraph1.YAxes(0).MajorDivisions.Interval += 5
            ScatterGraph1.Refresh()
        End If

 

Don't know if it matters but I am updating two scatterplots simultaneously.

0 Kudos
Message 1 of 11
(8,190 Views)

Hello lwild,

 

Could you attach your code (or a simplified version) so that the issue is more easily reproduced? If you can reproduce the issue with a small program, it is helpful. Also, does it crash every time? Have you been able to narrow down what line it crashes exactly on using debugging tools?

 

Regards,

 

Jason D

Applications Engineer

National Instruments

www.ni.com/support

0 Kudos
Message 2 of 11
(8,164 Views)

Hi,

 

What is the value for YAxis1.Range.Maximum? Where is this value being set?

That might be the problem.

 

Curt

0 Kudos
Message 3 of 11
(8,155 Views)

The y-axis maximum range value is set at the beginning right before the graph is updated. I tried to reproduce the issue with a simple trackbar and scattergraph program. I linked the y value to the trackbar and used time stamps for the x axis. I can't break the graph with the simple program, it will go way above 75 or 100 with no issue.

 

In the call stack it displays "External Code", when I show that it shows this:

 

>    System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID, int reason = -1, int pvLoopData = 0) + 0x444 bytes    

For what it's worth in my regular program I am using a background worker to call the hardware and calculate the values that are to be displayed on the graph. I do not know why this is occuring other than I am trying to programmatically set the y-axis value.

0 Kudos
Message 4 of 11
(8,144 Views)

Hi lwild,

 

Could you disable portions of your code to find the point that causes the crash? Alternatively you could start with disabling a large portion of your code and enabling it piece by piece to determine the root cause of the issue.

 

Regards,

 

Jason D

Applications Engineer

National Instruments

Message 5 of 11
(8,127 Views)

I've found that it crashes at the point where I attempt to plot the data to the graph. Just realized I did not include that portion of the code but here it is:

 

            'Dim nowValue As Date = Now()
            'Dim convertedValue As Double = CDbl(DataConverter.Convert(nowValue, GetType(Double)))

            'ScatterPlot1.PlotXYAppend(convertedValue, Val1(0))
            'ScatterPlot2.PlotXYAppend(convertedValue, Val2(1))

 I've tried removing the time variable and replacing it with a simple integer counter but it still crashes. The only way I can get the graph not to crash is if I remove the Append code.. but then I don't have a graph. I've also tried replacing the Val1 value with a simple integer value and it still crashes. It seems that it doesn't just happen over the value of 75 with the regular code but also pretty much at any point now.

 

Hopefully this makes more sense to everyone now, cause I am flat stumped.

0 Kudos
Message 6 of 11
(8,109 Views)

try this

 

Convert.ToDouble(Val1(0))) in the PlotXYAppend statement.

 

Curt

Message 7 of 11
(8,106 Views)

Hi Curt, tried what you suggested, now the graph crashes immediately.

0 Kudos
Message 8 of 11
(8,104 Views)

 

That shouldn't make it crash. I've used the exact code in one of my apps.

We must have found the same example

 

IonGaugePressure = modFunctions.Calculate_IonGaugePressure(CType(AverageVal(3), Double))

nowValue = Now()

convertedValue = CDbl(DataConverter.Convert(nowValue, GetType(Double)))

PressurePlot.PlotXYAppend(convertedValue, Convert.ToDouble(IonGaugePressure))

 

Have you checked to see if the val1 and val2 are null values?

 

Curt

Message 9 of 11
(8,099 Views)
Solution
Accepted by lwild

Hi,

 

I made a simple app with a scattergraph and a button on a form. It works just fine. There must be something wrong with your Y values.

 

Public Class Form1

    Dim yVal As Double

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim nowValue As Date
        Dim convertedValue As Double = 0

        Try
            nowValue = Now()

            convertedValue = CDbl(DataConverter.Convert(nowValue, GetType(Double)))
            yVal = yVal + 5


            ScatterPlot1.PlotXYAppend(convertedValue, Convert.ToDouble(yVal))

        Catch ex As Exception

        End Try

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try

            Me.XAxis1.MajorDivisions.LabelFormat = New NationalInstruments.UI.FormatString(NationalInstruments.UI.FormatStringMode.DateTime, "h:mm:ss tt")
           
        Catch ex As Exception

        End Try
    End Sub
End Class

 

 

Curt

Message 10 of 11
(8,090 Views)