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. Any tricks to increase QtChart responsiveness?
QtWS25 Last Chance

Any tricks to increase QtChart responsiveness?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtchartlineseriesplotresponsiveness
9 Posts 6 Posters 2.9k 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.
  • CJhaC Offline
    CJhaC Offline
    CJha
    wrote on last edited by CJha
    #1

    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 a QWidget, but I would like to give QtChart another shot because the QXYSeries class involves some basic interactions that I am unable to implement otherwise through QPainterPath. To check the responsiveness of the QtChart 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.

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

      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.

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

      CJhaC 1 Reply Last reply
      0
      • SGaistS SGaist

        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.

        CJhaC Offline
        CJhaC Offline
        CJha
        wrote on last edited by
        #3

        @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.

        Pl45m4P 1 Reply Last reply
        0
        • CJhaC CJha

          @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.

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by Pl45m4
          #4

          @CJha

          Nobody can look at 100.000 data points.
          Use downsampling to reduce the amount of points shown at a time. While zooming in or so, you can increase that amount again until you show that area with all the data.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          CJhaC 1 Reply Last reply
          0
          • Pl45m4P Pl45m4

            @CJha

            Nobody can look at 100.000 data points.
            Use downsampling to reduce the amount of points shown at a time. While zooming in or so, you can increase that amount again until you show that area with all the data.

            CJhaC Offline
            CJhaC Offline
            CJha
            wrote on last edited by
            #5

            @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 in QWidget it takes slightly more than 100 milliseconds, the same raw method in QChart takes between 500 - 600 milliseconds.

            J.HilkJ 1 Reply Last reply
            0
            • CJhaC CJha

              @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 in QWidget it takes slightly more than 100 milliseconds, the same raw method in QChart takes between 500 - 600 milliseconds.

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @CJha Charts is far from optimized, especially the QWidget version, have you tried a QQuickWidget/View and the QML Chart view?

              usually results in better overall performance


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              CJhaC 1 Reply Last reply
              0
              • J.HilkJ J.Hilk

                @CJha Charts is far from optimized, especially the QWidget version, have you tried a QQuickWidget/View and the QML Chart view?

                usually results in better overall performance

                CJhaC Offline
                CJhaC Offline
                CJha
                wrote on last edited by
                #7

                @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.

                A.A.SEZENA 1 Reply Last reply
                0
                • CJhaC CJha

                  @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.

                  A.A.SEZENA Offline
                  A.A.SEZENA Offline
                  A.A.SEZEN
                  wrote on last edited by
                  #8

                  @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.

                  1 Reply Last reply
                  0
                  • CJhaC CJha

                    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 a QWidget, but I would like to give QtChart another shot because the QXYSeries class involves some basic interactions that I am unable to implement otherwise through QPainterPath. To check the responsiveness of the QtChart 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.

                    S Offline
                    S Offline
                    samon_sg
                    wrote on last edited by
                    #9

                    @CJha try to useOpenGL for series, for qml i use series.useOpenGL = true

                    1 Reply Last reply
                    1

                    • Login

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