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: RealTimeCurveQElapsedTimer 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
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? -
@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)? -
@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? -
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()); }