Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. A QChart example
Forum Updated to NodeBB v4.3 + New Features

A QChart example

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 860 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • tomyT Offline
    tomyT Offline
    tomy
    wrote on last edited by
    #1

    Hi people,

    Please take a look at this Zoom Line Example.
    In the code, the following is the real accountable part for drawing the curve, here a Sin one:

    QLineSeries *series = new QLineSeries();
      for (int i = 0; i < 500; i++) {
          QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100);
          *series << p;
      }
    

    And this is the output:

    Capture3.PNG

    The X values are increasing from 0 to 499. And the Y values are fluctuating from -100 to +100. But the Sin formula above can't go negative! So how is the wave drawn this way, please?

    1 Reply Last reply
    0
    • tomyT tomy

      @mrjj

      Hi,

      So that qSin is different from Math Sin!

      Capture4.PNG

      Ow, I found I think. It's in Radians.

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #8

      @tomy
      yes
      "Returns the sine of the angle v in radians."

      1 Reply Last reply
      2
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi
        qDebug dont agree with you :)

          for (int i = 0; i < 500; i++) {
                 QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100);
                 qDebug() << p;
             }
        

        .....
        QPointF(244,36.8125)
        QPointF(245,30.9017)
        QPointF(246,24.869)
        QPointF(247,18.7381)
        QPointF(248,12.5333)
        QPointF(249,6.27905)
        QPointF(250,-1.16403e-13)
        QPointF(251,-6.27905)
        QPointF(252,-12.5333)
        QPointF(253,-18.7381)
        QPointF(254,-24.869)
        QPointF(255,-30.9017)

        tomyT 1 Reply Last reply
        1
        • mrjjM mrjj

          Hi
          qDebug dont agree with you :)

            for (int i = 0; i < 500; i++) {
                   QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100);
                   qDebug() << p;
               }
          

          .....
          QPointF(244,36.8125)
          QPointF(245,30.9017)
          QPointF(246,24.869)
          QPointF(247,18.7381)
          QPointF(248,12.5333)
          QPointF(249,6.27905)
          QPointF(250,-1.16403e-13)
          QPointF(251,-6.27905)
          QPointF(252,-12.5333)
          QPointF(253,-18.7381)
          QPointF(254,-24.869)
          QPointF(255,-30.9017)

          tomyT Offline
          tomyT Offline
          tomy
          wrote on last edited by tomy
          #3

          @mrjj
          thanks mrjj. :)

          for i = 251 let's check the value of y:

          QPointF p((qreal) 251, qSin(M_PI / 50 * 251) * 100) =
          QPointF p(251, qSin(3.14 / 50 * 251) * 100) =
          QPointF p(251, qSin(15.76) * 100) =
          QPointF p(251, 0.271 * 100) =
          QPointF p(251, 27.1)

          mrjjM 1 Reply Last reply
          0
          • tomyT tomy

            @mrjj
            thanks mrjj. :)

            for i = 251 let's check the value of y:

            QPointF p((qreal) 251, qSin(M_PI / 50 * 251) * 100) =
            QPointF p(251, qSin(3.14 / 50 * 251) * 100) =
            QPointF p(251, qSin(15.76) * 100) =
            QPointF p(251, 0.271 * 100) =
            QPointF p(251, 27.1)

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Hi
            for (int i = 251; i < 255; i++) {
            QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100);
            qDebug() << p;
            }

            gives

            QPointF(251,-6.27905)
            QPointF(252,-12.5333)
            QPointF(253,-18.7381)
            QPointF(254,-24.869)

            so something is up :)

            tomyT 1 Reply Last reply
            1
            • mrjjM mrjj

              Hi
              for (int i = 251; i < 255; i++) {
              QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100);
              qDebug() << p;
              }

              gives

              QPointF(251,-6.27905)
              QPointF(252,-12.5333)
              QPointF(253,-18.7381)
              QPointF(254,-24.869)

              so something is up :)

              tomyT Offline
              tomyT Offline
              tomy
              wrote on last edited by
              #5

              @mrjj
              Hi. :)

              But why when I manually calculate i =251, it gives me 27.1 and not -6.27905 for y!?
              Isn't M_PI = 3.14?
              Or the y coordinates are modified by some other part of the whole code? No, I think. Rather odd.

              1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #6

                Hi
                well its (3.14159265358979323846)
                (3.14159265358979323846 / 50 * 251) = 15.7708
                qSin(15.7708) * 100; = -6.27954

                tomyT 1 Reply Last reply
                1
                • mrjjM mrjj

                  Hi
                  well its (3.14159265358979323846)
                  (3.14159265358979323846 / 50 * 251) = 15.7708
                  qSin(15.7708) * 100; = -6.27954

                  tomyT Offline
                  tomyT Offline
                  tomy
                  wrote on last edited by tomy
                  #7

                  @mrjj

                  Hi,

                  So that qSin is different from Math Sin!

                  Capture4.PNG

                  Ow, I found I think. It's in Radians.

                  mrjjM 1 Reply Last reply
                  1
                  • tomyT tomy

                    @mrjj

                    Hi,

                    So that qSin is different from Math Sin!

                    Capture4.PNG

                    Ow, I found I think. It's in Radians.

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    @tomy
                    yes
                    "Returns the sine of the angle v in radians."

                    1 Reply Last reply
                    2

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved