RMChart - Trendline

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Robert DeBolt
    Member
    • Dec 2004
    • 529

    RMChart - Trendline

    I am attempting to draw a xy scatter chart with a trendline.
    Here is the code:

    Code:
        IF nRetVal < 0 THEN GOTO IsError
        '****** Set name and parameters for the X-datafile for series 1 ******
        nRetVal = RMC_SetSeriesDataFile(%ID_RMC1,1,1,"W:\projects\BOB\Applied Linear Regression\Table2-1\TABLE2-1.CSV","0,0","2",",",%FALSE)
        IF nRetVal < 0 THEN GOTO IsError
        '****** Set name and parameters for the Y-datafile for series 1 ******
        nRetVal = RMC_SetSeriesDataFile(%ID_RMC1,1,1,"W:\projects\BOB\Applied Linear Regression\Table2-1\TABLE2-1.CSV","0,0","3",",",%TRUE)
        IF nRetVal < 0 THEN GOTO IsError
    
    [B]    ' Now, calc the trend:
        LOCAL nFirst,nLast AS DOUBLE
        LOCAL nL,nT,nR,nB AS LONG
        nRetVal = RMC_CalcTrend(%ID_RMC1,1,1,nFirst,nLast,nL,nT,nR,nB)
        IF nRetVal < 0 THEN GOTO IsError
        ' Of course you could use nFirst and nLast to add a line series to show the trend,
        ' but it's more convenient to use nL, nT, nR and nB for drawing the line with a
        ' CustomObject line:
        nRetVal = RMC_CODash(%ID_RMC1,1,nL,nT,nR,nB,%RMC_LINE_FLAT_DASH,IIF(nFirst>nLast,_
                            %ColorRed,%ColorGreen),0,2,0,%RMC_ANCHOR_ARROW_CLOSED)
        IF nRetVal < 0 THEN GOTO IsError[/B]
    For the statement nRetVal = RMC_CalcTrend(%ID_RMC1,1,1,nFirst,nLast,nL,nT,nR,nB), the nRetVal returns -31.

    Must a COLine object be defined first?
    How do I go about it?

    Thanks.
    Regards,
    Bob
  • Knuth Konrad
    Member
    • Apr 2000
    • 4846

    #2
    RMChart's helpfile says:

    RMC_ERROR_WRONGSERIESTYPE -31

    Error when trying to calculate an average or trend for a not supported series type (e.g. Pie/Donut).
    The topic RMC_CalcTrend expands on this:
    Return value

    RMC_ERROR_WRONGSERIESTYPE: The series is not grid based (either Pie/Donut/Pyramid or XY).
    So, it looks like you're using an unsupported chart type.

    Comment

    • Robert DeBolt
      Member
      • Dec 2004
      • 529

      #3
      Thanks, Knuth, for your reply.

      I thought that I defined the charts as xy scatter chart.

      I have enclosed all files in a zip file.
      The code that fails is commented out and
      is located following the Region 1 code in
      procedure DoTheChart.

      I appreciate your help very much.
      Attached Files
      Regards,
      Bob

      Comment

      • Knuth Konrad
        Member
        • Apr 2000
        • 4846

        #4
        Originally posted by Robert DeBolt View Post
        I thought that I defined the charts as xy scatter chart.
        ... which seems to cause the problem:

        RMC_ERROR_WRONGSERIESTYPE: The series is not grid based (either Pie/Donut/Pyramid or XY).
        In other words: You can't calculate a trend line from chart types Pie, Donut and XY

        Comment

        • Robert DeBolt
          Member
          • Dec 2004
          • 529

          #5
          Thanks, Knuth, for staying with me.

          After scratching below the surface a little below the surface, I discovered the simple solution: instead of trying to get RMChart to calculate the trend line, I did it myself! I calculated two points on the trend line and RMC drew it for me.

          Attached is a jpg of the final output.

          Again, many thanks.
          Attached Files
          Regards,
          Bob

          Comment

          • Tim Lakinir
            Member
            • Sep 2018
            • 1555

            #6
            Hi All
            I'm trying to learn RMchart , but Mr Debolt above did not provide the his latest code for this post #5, I wonder if any one else can help
            at least to get me started on RMChart such as how to draw the trend line?

            Comment

            • Stuart McLachlan
              Member
              • Mar 2000
              • 9467

              #7
              Originally posted by Tim Lakinir View Post
              Hi All
              I'm trying to learn RMchart , but Mr Debolt above did not provide the his latest code for this post #5, I wonder if any one else can help
              at least to get me started on RMChart such as how to draw the trend line?
              Drawing a trend line is simple, you just use standard RMChart commands to draw a line from one point to another.

              Calculating what line to draw is not so simple. You need to do the math for that yourself, it's not part of the package.
              For a simple linear trendline, calculate the slope and intercept of the line from the data points and then plot it.

              Here's the formula:

              Click image for larger version  Name:	trendline.jpg Views:	0 Size:	3.7 KB ID:	794582

              If that doesn't help, there's a simple step by step explanation of the process here:
              https://classroom.synonym.com/calcul...line-2709.html

              For a polynomial, exponential, logarithmic or power trend line it gets a bit more complicated.

              .
              =========================
              https://camcopng.com
              =========================

              Comment

              • Tim Lakinir
                Member
                • Sep 2018
                • 1555

                #8
                Thanks Sir Mclachlan , that's more like high school math

                Comment

                • Tim Lakinir
                  Member
                  • Sep 2018
                  • 1555

                  #9
                  As Rmchart.com is gone, I'm wondering if I get to read its web info via something like waybackmachine ?

                  Comment

                  • Stuart McLachlan
                    Member
                    • Mar 2000
                    • 9467

                    #10
                    Yes, it's basic statistics. Just for fun, i knocked up a little function to calculate the trend line for a series of datapoints stored in a two diensional array
                    '
                    Code:
                    #COMPILE EXE
                    #DIM ALL
                    
                    FUNCTION PBMAIN () AS LONG
                    LOCAL n, i AS LONG
                    LOCAL slope, offset AS EXT
                    LOCAL xMin,xMax AS EXT
                    LOCAL yMin,yMax AS EXT
                    
                    'Build a data set
                        n = 99 ' 100 points -1 because we are using a zero based array
                        xMin = 0: xMax = 100 ' range to plot on x Axis.
                        DIM dp(n,1) AS EXT ' x values in dp(i,0), y values in dp(i,1)
                        RANDOMIZE TIMER
                        'Comment out one of the two following plot types
                        'scatter plot
                    '    FOR i = 0 TO n
                    '        dp(i,0) = RND(1,100)
                    '        dp(i,1) =  RND(1,100)
                    '    NEXT
                        'linear plot
                        FOR i = 0 TO n
                            dp(i,0) = i
                            dp(i,1) =  RND(1,20) + i * RND(1,5) ' slowly increment average y
                        NEXT
                        'Get linear trendline formula
                        Trendline dp(),slope,offset
                        yMin = offset: yMax = slope * xMax + offset
                        ? "Trendline is:  y = " & FORMAT$(slope,"0.00") & IIF$(offset >= 0,"x +","x ")  & FORMAT$(offset,"0.00") & $CRLF _
                        &  USING$("Line from (#.# , #.# ) to (#.# , #.#)",xMin,yMin,xMax,yMax)
                    END FUNCTION
                    
                    FUNCTION TrendLine(a() AS EXT,s AS EXT, o AS EXT) AS LONG
                    LOCAL i,n,sX,sY,sXY,sX2,sY2 AS EXT
                        n = UBOUND(a())
                        FOR i = 0 TO n
                            sX +=  a(i,0)
                            sy +=  a(i,1)
                            sXY += a(i,0) * a(i,1)
                            sx2 += a(i,0)^2
                            sY2 += a(i,1)^2
                        NEXT
                        s =  (n * sXY - sX*sY)/(n*sX2 - sX^2)
                        o = (sY - s *sX)/n
                    END FUNCTION
                    '
                    Last edited by Stuart McLachlan; 1 Jun 2020, 08:47 AM.
                    =========================
                    https://camcopng.com
                    =========================

                    Comment

                    • Tim Lakinir
                      Member
                      • Sep 2018
                      • 1555

                      #11
                      Thank you Sir Stuart

                      Comment

                      • Johan Klassen
                        Member
                        • Jun 2002
                        • 214

                        #12
                        Tim Lakinir
                        yes, wayback machine does have a backup https://web.archive.org/web/20061230...w.rmchart.com/
                        as the salmon fish is compelled to go back to it's birthplace to spawn, so comes a day when man is compelled to go back to it's source.. GOD

                        Comment

                        • Stuart McLachlan
                          Member
                          • Mar 2000
                          • 9467

                          #13
                          Originally posted by Johan Klassen View Post
                          That one is a bit early(2006) and refers to Ver 3.

                          This one from Feb 2009 appears to be the last one and covers the last version (4.12) https://web.archive.org/web/20090205...mchart.com:80/
                          (Note: the download links don't work)
                          =========================
                          https://camcopng.com
                          =========================

                          Comment

                          • Johan Klassen
                            Member
                            • Jun 2002
                            • 214

                            #14
                            hello Stuart McLachlan
                            thanks for the link, the setup.exe downloads ok https://web.archive.org/web/20090205...mchart.com:80/
                            as the salmon fish is compelled to go back to it's birthplace to spawn, so comes a day when man is compelled to go back to it's source.. GOD

                            Comment

                            • Stuart McLachlan
                              Member
                              • Mar 2000
                              • 9467

                              #15
                              Originally posted by Johan Klassen View Post
                              hello Stuart McLachlan
                              thanks for the link, the setup.exe downloads ok https://web.archive.org/web/20090205...mchart.com:80/
                              H, so it does. I didn't try that one, I just tried the rmchart_dll.zip download link and that one didn't work.
                              =========================
                              https://camcopng.com
                              =========================

                              Comment

                              • Tim Lakinir
                                Member
                                • Sep 2018
                                • 1555

                                #16
                                Thank you Johan and Stuart, Rmchart is indeed a beauty

                                Comment

                                • Pierre Bellisle
                                  Member
                                  • Dec 2001
                                  • 5272

                                  #17
                                  For those interested, you may download RmChart 4.12 from this site.

                                  Zipped files kit, no installer.
                                  Same kit via an installer.

                                  If for compatibitity reason, someone want an older version, pm me.
                                  I got also v2.0, v2.1, v2.2, v3.0, v3.10c, v4.0, v4.01, v4.10

                                  Comment

                                  • Gary Beene
                                    Member
                                    • May 2008
                                    • 20026

                                    #18
                                    Hey, Tim!

                                    Do you know about gbChartMaster?

                                    https://forum.powerbasic.com/forum/u...ic-application

                                    Click image for larger version

Name:	gbchartmaster_mains.jpg
Views:	190
Size:	25.7 KB
ID:	794691

                                    With Stuart's code above, it should be easy enough to add a trendline graph to what gbChartMaster already has.

                                    Comment

                                    • Stuart McLachlan
                                      Member
                                      • Mar 2000
                                      • 9467

                                      #19
                                      Originally posted by Gary Beene View Post
                                      Hey, Tim!

                                      Do you know about gbChartMaster?
                                      Wow! I wasn't aware of that one. I'm about to go play with it


                                      =========================
                                      https://camcopng.com
                                      =========================

                                      Comment

                                      • Stuart McLachlan
                                        Member
                                        • Mar 2000
                                        • 9467

                                        #20
                                        Originally posted by Stuart McLachlan View Post
                                        Wow! I wasn't aware of that one. I'm about to go play with it
                                        Correction. I had forgotten about that one
                                        Must be "oldtimers disease" !

                                        I went to install it and found I already had it from an install a few years ago.

                                        =========================
                                        https://camcopng.com
                                        =========================

                                        Comment

                                        Working...
                                        X