Announcement

Collapse
No announcement yet.

RMChart - Trendline

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #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


    • #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


      • #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


        • #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


          • #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


            • #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.

              .

              Comment


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

                Comment


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

                  Comment


                  • #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.

                    Comment


                    • #11
                      Thank you Sir Stuart

                      Comment


                      • #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


                        • #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)

                          Comment


                          • #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


                            • #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.

                              Comment


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

                                Comment


                                • #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


                                  • #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:	79
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


                                    • #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


                                      Comment


                                      • #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.

                                        Comment

                                        Working...
                                        X