Important: Please read the Qt Code of Conduct -

Multiple real time plots/charts

  • Hey guys,

    Since QT uses a single thread for the GUI I'm experiencing, as expected, low performance when displaying 8 and more charts fed with real time data.
    I've tried the QCharts, qcustomplot, qwtPlot. All with and without openGL enabled.
    So far the best performance comes with qcustomplot.

    What would you suggest me to do, to display 10-20 real time charts without performance drop?
    Fork a single chart app and use ipc for data exchange?

    Best regards

  • Lifetime Qt Champion

    @framet How often do you update all these charts?

  • @jsulm The real time data comes in over UDP at about 50 Hz in a separate thread. Then the data will be distributed with a QTimer with 20 HZ.

  • using QChart, how do you update real time data?

    if you receive the "8 and more" data point at the same time (or at least synchronously) you can subclass QAbstractTableModel and update all the values in a signle operation and cause a single repaint of the chart itself (using a model mapper as bridge between the model and the chart)

  • @VRonin I have "8 and more" charts simultaneously open and not one chart with 8 and more data points. Each chart does not have more than 3 data point series. As I understand the QAbstractTableModel is only for one single chart correct? So this probably wont safe me the majority of the performance but is still a good point for QCharts.

  • @framet said in Multiple real time plots/charts:

    QAbstractTableModel is only for one single chart correct?

    Nope. actually it QAbstractTableModel is perfect for when you have more than 1 chart.

    How did you try to update the charts before?

  • @VRonin I'm currently not in the office so I cannot check to be 100% but i think i just added the to the respective QLineSeries.

  • @VRonin said in Multiple real time plots/charts:

    Nope. actually it QAbstractTableModel is perfect for when you have more than 1 chart.

    hey @VRonin im currently working on a test with QAbstractTableModel.
    I have a model with 100 rows and 4 columns. If new values would overflow the memory a just start at row zero again.
    The problem what I have and I can't find any solution for it is that when I update a specific row and emit dataChanged(topLeft,bottomRight) with the updated values QChart updates/repaints the hole model which leads to flickering when you go above 10 HZ.

    Is there a way to reimplement this QChart behavior or is there a flag to set?


    Edit: here is an example with 2 HZ

    Edit 2: just found out with linesSeries.setUseOpenGL() decreases the flickering

  • Wow, it's unbelievably slow... I'll prepare a minimal example and see if I get the same

  • Below are two tests with TableModel (100,4)

    Both tests run with 20 HZ
    With OpenGL on LineSeries enabled

    Test 1) Single chart
    Test 2) 6 charts

    With OpenGL on LineSeries disabled
    Test 3) 6 charts

    As you can see the problem of QT getting slower with more charts relaying on the same Model still exists.

    Edit: just to clarify YES the test before was with 2 HZ and those tests here are with 20 HZ :)

  • Tryed:

    #include <QWidget>
    #include <QTimer>
    #include <QStandardItemModel>
    #include <QtCharts/QChart>
    #include <QtCharts/QChartView>
    #include <QGridLayout>
    #include <QtCharts/QVXYModelMapper>
    #include <QtCharts/QLineSeries>
    #include <cmath>
    class TestChart : public QWidget
        explicit TestChart(QWidget *parent = Q_NULLPTR)
            , maixLength(360)
            , frequency(20.0)
            , shift(0.0)
            , currentCounter(0.0)
            , pi(std::acos(-1))
            m_model = new QStandardItemModel(this);
            m_model->insertColumns(0, 3);
            //m_model->insertRows(0, maixLength);
            m_updateTimer = new QTimer(this);
            m_updateTimer->setInterval(1000.0 / frequency);
            connect(m_updateTimer, &QTimer::timeout, this, &TestChart::addSeriesData);
            QGridLayout* mainLay = new QGridLayout(this);
            for (int i = 0; i < 15; ++i) {
                QLineSeries *sineSeries = new QLineSeries;
                sineSeries->setName("Sine Wave");
                QVXYModelMapper *mapper = new QVXYModelMapper(this);
                QLineSeries *cosineSeries = new QLineSeries;
                cosineSeries->setName("Cosine Wave");
                mapper = new QVXYModelMapper(this);
                QChart *chart = new QChart();
                chart->setTitle("Simple line chart example");
                QChartView *chartView = new QChartView(chart);
                mainLay->addWidget(chartView,i/5,i%5 );
    private slots:
        void addSeriesData()
            if (m_model->rowCount() <= currentCounter)
                m_model->insertRows(m_model->rowCount(), currentCounter - m_model->rowCount() + 1);
            m_model->setData(m_model->index(currentCounter, 0), currentCounter);
            m_model->setData(m_model->index(currentCounter, 1), std::sin((shift+currentCounter)*pi / 180.0));
            m_model->setData(m_model->index(currentCounter, 2), std::cos((shift + currentCounter)*pi / 180.0));
            currentCounter += 1.0;
            if (currentCounter >= maixLength) {
                currentCounter = 0.0;
                shift += 90;
        const double pi;
        double shift;
        double currentCounter;
        double frequency;
        QTimer* m_updateTimer;
        QAbstractItemModel* m_model;
        const int maixLength;

    15 charts, you are right, 20Hz it's not great even if in release mode is better.

  • Do you have any idea how to get 15 charts without severe performance issues?
    Except outsourcing single Charts to seperate Qt-Applications and send data over ipc or something in this direction.

  • I think yo have to decouple the data arrival frequency to the frequency you send the data to the chart.

    In the QAbstractTableModel instead of emitting dataChanged() directly, every time a new datapoint arrives (re)start a signle shot timer that emits the signal. I'll try implementing it and update this post


    My method increased but not to an acceptable level. I have to give up

  • @VRonin thank you for your time and effort!!!

    I still have some ideas left. Will post it here when one gives an acceptable result.


  • @framet Hey framet. Did you find a solution?

  • I am working with a application that has 12 curves and I am have the same problem, if I increase the number of curves, the performance decrease. I use qcustomplot. I need to plot 300pixels/second. Does anyone have some ideas?

Log in to reply