Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Plot live data on QtChart
Qt 6.12 LTS is out! See what's new in the release blog

Plot live data on QtChart

Scheduled Pinned Locked Moved Unsolved General and Desktop
22 Posts 3 Posters 21.4k Views 1 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.
  • R rockon209

    @jsulm
    ok thanks for the explanation
    but it is confusing because in XYSeriesIODevice class have m_series as XYseries and widget class has m_series as Qlineseries
    and tried your above suggestion i am getting the following error
    error: invalid types 'double[int]' for array subscript
    points.append(QPointF(k + size, ((quint8)tempSensor[resolution * k] - 128)/128.0));

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #12

    @rockon209 said in Plot live data on QtChart:

    QPointF

    Can you show the whole method?

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • R Offline
      R Offline
      rockon209
      wrote on last edited by rockon209
      #13

      @jsulm
      with timer i call the following function every second
      void test:: readTemp()
      {
      double tempSensor= readSignal Sensor(tempChannel);
      writeData();
      }
      void test::writeData()
      {
      qint64 range = 2000;
      QVector<QPointF> oldPoints = m_series->pointsVector();
      QVector<QPointF> points;
      int resolution = 4;
      qint64 maxSize;

      if (oldPoints.count() < range) {
          points = m_series->pointsVector();
      } else {
          for (int i = maxSize/resolution; i < oldPoints.count(); i++)
              points.append(QPointF(i - maxSize/resolution, oldPoints.at(i).y()));
      }
      
      qint64 size = points.count();
      
      for (int k = 0; k < maxSize/resolution; k++)
          points.append(QPointF(k + size, ((quint8)tempSensor[resolution * k] - 128)/128.0));
      
      m_series->replace(points);
      

      //return maxSize;
      }

      jsulmJ 1 Reply Last reply
      0
      • R rockon209

        @jsulm
        with timer i call the following function every second
        void test:: readTemp()
        {
        double tempSensor= readSignal Sensor(tempChannel);
        writeData();
        }
        void test::writeData()
        {
        qint64 range = 2000;
        QVector<QPointF> oldPoints = m_series->pointsVector();
        QVector<QPointF> points;
        int resolution = 4;
        qint64 maxSize;

        if (oldPoints.count() < range) {
            points = m_series->pointsVector();
        } else {
            for (int i = maxSize/resolution; i < oldPoints.count(); i++)
                points.append(QPointF(i - maxSize/resolution, oldPoints.at(i).y()));
        }
        
        qint64 size = points.count();
        
        for (int k = 0; k < maxSize/resolution; k++)
            points.append(QPointF(k + size, ((quint8)tempSensor[resolution * k] - 128)/128.0));
        
        m_series->replace(points);
        

        //return maxSize;
        }

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #14

        @rockon209 said in Plot live data on QtChart:

        double tempSensor= readSignal Sensor(tempChannel);

        this is not going to work - you store the temperature in a local variable!

        Also, this is wrong if tempSensor isn't an array:

        points.append(QPointF(k + size, ((quint8)tempSensor[resolution * k] - 128)/128.0));
        

        As I said you need to adjust the code for your needs...

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rockon209
          wrote on last edited by
          #15

          @jsulm
          then how to make array as i am reading from the sensor every second and getting only one value.

          jsulmJ 1 Reply Last reply
          0
          • R rockon209

            @jsulm
            then how to make array as i am reading from the sensor every second and getting only one value.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by jsulm
            #16

            @rockon209 You don't need any array:

            void test:: readTemp()
            {
            writeData( readSignal Sensor(tempChannel));
            }
            
            void test::writeData(const double tempSensor)
            {
            qint64 range = 2000;
            QVector<QPointF> oldPoints = m_series->pointsVector();
            QVector<QPointF> points;
            int resolution = 4;
            qint64 maxSize;
            
            if (oldPoints.count() < range) {
                points = m_series->pointsVector();
            } else {
                for (int i = maxSize/resolution; i < oldPoints.count(); i++)
                    points.append(QPointF(i - maxSize/resolution, oldPoints.at(i).y()));
            }
            
            qint64 size = points.count();
            points.append(QPointF(k + size, ((quint8)tempSensor - 128)/128.0));
            m_series->replace(points);
            }

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • R Offline
              R Offline
              rockon209
              wrote on last edited by
              #17

              @jsulm
              i am getting following error and the application is shutting down
              terminate called after throwing an instance of 'std::bad_alloc'
              what(): std::bad_alloc

              jsulmJ 1 Reply Last reply
              0
              • R rockon209

                @jsulm
                i am getting following error and the application is shutting down
                terminate called after throwing an instance of 'std::bad_alloc'
                what(): std::bad_alloc

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #18

                @rockon209 Please debug you app to see where it crashes...

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  rockon209
                  wrote on last edited by
                  #19

                  @jsulm
                  when i read the sensor data it crashes

                  jsulmJ 1 Reply Last reply
                  0
                  • R rockon209

                    @jsulm
                    when i read the sensor data it crashes

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #20

                    @rockon209 Then find out why and fix it...

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      rockon209
                      wrote on last edited by
                      #21

                      @jsulm
                      do you know how maxSize value is calculated because i my code maxsize value is very very very big and in think that is the problem

                      jsulmJ 1 Reply Last reply
                      0
                      • R rockon209

                        @jsulm
                        do you know how maxSize value is calculated because i my code maxsize value is very very very big and in think that is the problem

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #22

                        @rockon209 In the code in the example it is passed as parameter:

                        qint64 XYSeriesIODevice::writeData(const char * data, qint64 maxSize)
                        

                        In your code you don't assign anything to it so it has arbitrary value.

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0

                        • Login

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