Any tricks to increase QtChart responsiveness?
-
Hi! I need to make a line plot of a large amount of data in a short period of time. The goal is to have 100,000 data points plotted in a line series in less than 50 milliseconds. I am able to do this through
QPainterPath
by painting on aQWidget
, but I would like to giveQtChart
another shot because theQXYSeries
class involves some basic interactions that I am unable to implement otherwise throughQPainterPath
. To check the responsiveness of theQtChart
I made a small test application, here is the entire code for that:mainWindow.h
#include <QtWidgets/QMainWindow> #include <QtCharts/qchartview.h> #include <QtCharts/qlineseries.h> #include <QtMath> #include <QElapsedTimer> #include <QDebug> #include "ui_mainWindow.h" using namespace QtCharts; class mainWindow : public QMainWindow { Q_OBJECT public: mainWindow(QWidget *parent = Q_NULLPTR); private: Ui::mainWindowClass ui; QLineSeries *series; QChartView *view; QChart *chart; double data; protected: virtual void resizeEvent(QResizeEvent *event) override; };
mainWindow.cpp
#include "mainWindow.h" mainWindow::mainWindow(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); /* Creating Line Series */ series = new QLineSeries(); for(int ii = 0; ii < 100000; ++ii) { data = 2 * sin(2 * M_PI * 3 * ii / 100000); *series << QPointF(ii, data); } /* Creating Chart */ chart = new QChart(); chart->addSeries(series); chart->createDefaultAxes(); chart->setAnimationOptions(QChart::NoAnimation); /* Creating Chart View */ view = new QChartView(chart); view->setChart(chart); view->setRenderHint(QPainter::Antialiasing); view->setParent(ui.horizontalFrame); } void mainWindow::resizeEvent(QResizeEvent *event) { QElapsedTimer timer; timer.start(); chart->resize(width(), height()); qDebug() << timer.elapsed() << "milliseconds"; }
I am getting a response time of more than 500 milliseconds. I have already disabled all animations. Is there any way I can improve this response time significantly?
For reference, I am using Qt 5.15.0 with Visual Studio Community 2019.
-
Hi,
Likely not the answer you are looking for but you might want to check the Qwt project. It may have better performance for that kind of cases.
-
@SGaist Thanks! I have considered Qwt Project, however, it doesn't have proper documentation to tell me if it has the interactions that I need. On top of that, I am quite sure plotting the same amount of data on Qwt will take upwards of 100 milliseconds which is still beyond the limits of my requirements.
-
@Pl45m4 I know, I have developed my own method of downsampling for a line plot, so that peaks and overall data values are preserved. I can use it with
QWidget
and draw there much faster (15 - 20 ms). However, even if I use the raw method of plotting all the data points inQWidget
it takes slightly more than 100 milliseconds, the same raw method inQChart
takes between 500 - 600 milliseconds. -
@J-Hilk Thanks for the suggestion.
I haven't tried it, I am working with C++ only. As far as I understand for Qt Quick I will have to use QML which I haven't learned yet (I started with C++ a few a month back). Hopefully, the Qt 6 release in December this year will bring huge improvements to Qt Charts. -
@CJha We agree when it's a little late. I tried without changing your code. Output was 52 milliseconds. Maybe not a contribution, but the difference is not 1/10. QChart seems to do what you want.
Windows 10 x64, Qt 6.1, MinGW 64 and AMD Ryzen 7 PRO 4750U 8Gb RAM.