CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
+ Reply to Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2013
    Posts
    7

    plotting data in mschart

    Hi Everyone,

    Please help me how to get the perfect straight line in mschart.also to get the R2 of the the slope and y-intercept.here is my code.
    here is the number to input to test the code:

    conc1(0)=0
    conc1(1)=1
    conc1(2)=5
    conc1(3)=10
    conc1(4)=20

    abs1(0)=0.0011
    abs1(1)=0.0226
    abs1(2)=0.1320
    abs1(3)=0.2531
    abs1(4)=0.0000

    here's my code:


    Private Sub ABS1_KeyPress(Index As Integer, KeyAscii As Integer)
    Dim s0, s1, s2, t0, t1 As Double
    s0 = 0
    s1 = 0
    s2 = 0
    t0 = 0
    t1 = 0

    Select Case Index
    Case 0:

    If KeyAscii = 13 Then
    ABS1(1).SetFocus
    End If
    Case 1:
    If KeyAscii = 13 Then
    ABS1(2).SetFocus
    End If
    Case 2:
    If KeyAscii = 13 Then
    ABS1(3).SetFocus
    End If
    Case 3:
    If KeyAscii = 13 Then
    ABS1(4).SetFocus
    End If
    Case 4:
    If KeyAscii = 13 Then
    'How to get the data for the slope/y intercept computation
    For X = 0 To 4
    s0 = s0 + 1
    s1 = s1 + CONC2(X)
    s2 = s2 + (CONC2(X) * CONC2(X))
    t0 = t0 + ABS2(X)
    t1 = t1 + (CONC2(X) * ABS2(X))
    ''Plot Graph

    Next
    AnalyzerInc ' call graph
    SlopeOrig = Format((s0 * t1 - s1 * t0) / (s0 * s2 - s1 * s1), "0.#000") 'slope formula M
    YinterceptOrig = Format((s2 * t0 - s1 * t1) / (s0 * s2 - s1 * s1), "0.#000") 'Yintercept formula B
    SlopeCorrected = Format((s0 * t1 - s1 * t0) / (s0 * s2 - s1 * s1), "0.#000")
    Ycorrected = Format((s2 * t0 - s1 * t1) / (s0 * s2 - s1 * s1), "0.#000")
    'Regression Formula y = Mx + b
    RsquareOrig = Format((SlopeOrig * s0) + YinterceptOrig, "0.#000")
    RsquareCorrected = Format((SlopeCorrected * s0) + Ycorrected, "0.#000")
    End If
    End Select
    Graph(0, 2) = ABS2(0)
    Graph(1, 2) = ABS2(1)
    Graph(2, 2) = ABS2(2)
    Graph(3, 2) = ABS2(3)
    Graph(4, 2) = ABS2(4)
    MSChart1.ChartData = Graph
    MSChart2.ChartData = Graph

    For Y = 1 To 5
    MSChart1.Row = Y
    MSChart1.RowLabel = CONC2(Y - 1)
    MSChart2.Row = Y
    MSChart2.RowLabel = CONC2(Y - 1)

    Next
    'i got this slope and y intercept to the member of this forum also. thanks to him but i cant understand his R2 formulw(y=mx-b) i dont know where to get the x value.

    Please help me to get the prefect line after removing the abs3(4)(abs3 is where the computation displayed)also how to get the regression or R2. Thanks

    Note: I use line in chart..cause when i used the xy scattered the negative value did'nt plot on the last column instead it plot on the first row negative value.

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,584

    Re: plotting data in mschart

    Change this line first:

    Code:
    Dim s0, s1, s2, t0, t1 As Double
    As you are declaring only t1 as a Double, not them all!

    Code:
    Dim s0 As Double, s1 As Double, s2 As Double, t0 As Double, t1 As Double
    And then try running it again!
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2012 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Feb 2013
    Posts
    7

    Re: plotting data in mschart

    Hi dglliena

    I already change and nothing happen to my Regression result.(y=Mx-B) in my input which is x on that? Also my plot in graph is not straight from base on my screen shot.(pls. see attached file) Hope you can help me on this problem. Thanks.
    Attached Images  

  4. #4
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,584

    Re: plotting data in mschart

    I don't even see the values that you calculated for regression, etc...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2012 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Feb 2013
    Posts
    7

    Re: plotting data in mschart

    Here is the code to get the Slope/Y intercept and Regrssion
    and my inputs is on the first table in my screenshot
    For X = 0 To 4
    s0 = s0 + 1
    s1 = s1 + CONC2(X)
    s2 = s2 + (CONC2(X) * CONC2(X))
    t0 = t0 + ABS2(X)
    t1 = t1 + (CONC2(X) * ABS2(X))
    ''Plot Graph

    Next

    SlopeOrig = Format((s0 * t1 - s1 * t0) / (s0 * s2 - s1 * s1), "0.#000") 'slope formula M
    YinterceptOrig = Format((s2 * t0 - s1 * t1) / (s0 * s2 - s1 * s1), "0.#000") 'Yintercept formula B
    SlopeCorrected = Format((s0 * t1 - s1 * t0) / (s0 * s2 - s1 * s1), "0.#000")
    Ycorrected = Format((s2 * t0 - s1 * t1) / (s0 * s2 - s1 * s1), "0.#000")

    'Regression Formula y = Mx + b
    RsquareCorrected = Format((SlopeCorrected ) + Ycorrected, "0.#000") ''''Regression computation

  6. #6
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,584

    Re: plotting data in mschart

    Try it in Excel to see what happens.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2012 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Feb 2013
    Posts
    7

    Re: plotting data in mschart

    I already try that before in excel on how to have a straight line if your input the ff.data.in excel it used a xy scatter graph to have a straight line but my problem in VB is if i used xy scatter the last input would be plot under the first input unlike if i used line graph u will see the line of last input.did you get me?

  8. #8
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,584

    Re: plotting data in mschart

    Might be a resolution problem with the monitor, or else, VB6 can't do WPF properly, since it wasn't INVENTED yet
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2012 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #9
    Join Date
    Feb 2013
    Posts
    7

    Re: plotting data in mschart

    i see.how about the regression?how to get the regression base on my inputs?

  10. #10
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,584

    Re: plotting data in mschart

    Looks like

    Code:
    SlopeCorrected 
    
    Ycorrected
    might be the problem...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2012 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  11. #11
    Join Date
    Feb 2013
    Posts
    7

    Re: plotting data in mschart

    The formula on that has a correct result of what we expect only the regression is not.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts



HTML5 Development Center

Click Here to Expand Forum to Full Width