Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Why does setRange of QDateTimeAxis take so much time?



  • I used QChart to display real-time curves, and found that setRange() of QDateTimeAxis take so much time, about 30ms.
    Here is a link to the demo code: RealTimeCurve

            QElapsedTimer t;
            t.start();
            beginTime = QDateTime::currentDateTime();
            endTime = beginTime.addMSecs(MaxSize * static_cast<uint32_t>(timer->interval()));
            axisX->setMin(beginTime);
            axisX->setMax(endTime); // TODO: waste about 30ms
            // axisX->setRange(beginTime, endTime);
            qDebug() << "QElapsedTimer" << t.elapsed();
    

    Could you help me, please?
    Best Regards!



  • @tovax
    I might be wrong(!), but doesn't changing the range require complete rescaling/redrawing of the entire chart? If you already have a lot of points plotted(?), that could be quite a bit of work? Is there anyway you can set the range before you plot the points (or at least test that)?



  • @JonB
    Hi,
    Thanks very much for your reply.
    I want to achieve a display like this:real-time-curve-gif
    So I have to reset the range when the data is updated.



  • @tovax
    You asked "Why does setRange of QDateTimeAxis take so much time?". I am suggesting it is because it already has a lot of points. I suggested you try without (many) points to see if this is the case. Did you try that? If that is not the reason you should discover that first.

    I recall a long time ago the same question/problem being asked in this forum. I'm afraid I don't recall what/whether there was a good resolution. There is a (possibly old?) source code at https://www.advsofteng.com/doc/cdcppdoc/realtimezoomscrollqt.htm which you might look at to see if it helps you any? There is QChart::scroll(). Maybe Google for "qchart real time`, something like https://stackoverflow.com/questions/50853387/qchart-realtime-performance or other hits may help you?



  • @JonB
    This demo only has 10 points now.
    I will read these posts, thanks again.



  • Test Results:
    1.
    "test code" in function initialize():
    Debug output: QElapsedTimer "1" 0 0
    Consume 0ms.
    2.
    "test code" in timer slot onTimer():
    Debug output: QElapsedTimer "2" 53 46
    Consume 53ms.

    test code as follows:

    void JCDemoRealTimeCurve::test(uint32_t num)
    {
        QElapsedTimer t;
        t.start();
        beginTime = QDateTime::currentDateTime();
        endTime = beginTime.addMSecs(MaxSize * static_cast<uint32_t>(timer->interval()));
        axisX->setMin(beginTime);
        axisX->setMax(endTime); // TODO: waste about 30ms
        // axisX->setRange(beginTime, endTime);
        qDebug() << "QElapsedTimer" << QString::number(num) << t.elapsed() << beginTime.msecsTo(QDateTime::currentDateTime());
    }
    


  • @JonB
    Hi,
    This is a very good website! Thank you very much!
    https://www.advsofteng.com/
    Best Regards!


Log in to reply