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. Improve performance at shifting QLineSeries?
QtWS25 Last Chance

Improve performance at shifting QLineSeries?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 2.8k Views
  • 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.
  • H Offline
    H Offline
    HTWAMD
    wrote on last edited by HTWAMD
    #1

    Hey,

    I'm using QtCharts and animated the graphs. After having more than 50 values, always the oldest got removed from the series.
    Here a short code overview:

            QVector<QPointF> points = m_temperature_series.pointsVector();
            m_temperature_series.clear();
            for (int i=0;i<index;i++)
                m_temperature_series.append(i, points.at(i+1).y());
    

    The class of m_temperature_series is QLineSeries

    It's working good but it needs too much performance. With multiple graphs and a long graph history, you have a high cpu usage. But I dont know any way to optimize this code.
    I hope someone can help me out here :)

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Why not just remove the first element using takeFirst and then append your new element ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • H Offline
        H Offline
        HTWAMD
        wrote on last edited by HTWAMD
        #3

        TakeFirst is basically a good idea and it removes the first element. The problem is, that the second element at X still have the value 1 and is not decremented to 0.

        Edit// Just did a short test with another code... it's working but not sure about the performance

            QLineSeries Test;
        
            Test.append(0,0);
            Test.append(1,1);
            Test.append(2,2);
            Test.append(3,3);
        
            QList<QPointF> Points = Test.points();
            Points.removeFirst();
        
            int counter=0;
            QList<QPointF>::iterator i;
            for (i=Points.begin(); i!=Points.end();i++)
            {
                i->setX(counter);
                counter++;
            }
        
            Test.clear();
            Test.append(Points);
        
        
        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          How about using the model-view approach with QVXYModelMapper as shown in the model data example?

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          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 Extensions
          • Unsolved