QChart with QAreaSeries with large data is very slow

514 views Asked by At

I am playing around with QCharts (using area chart example as a template).

I am drawing an area chart with 10000 points in each of the series, and am finding that it is very slow, 30s for the window to appear and resizing the window results in the process hanging, its unusable for this dataset . Any ideas what could be wrong here ? I have seen that disabling anti aliasing might help, however it doesn't.

I have the folllowing code


#include <QtWidgets/QApplication>
#include <QtWidgets/QMainWindow>
#include <QtCharts/QChartView>
#include <QtCharts/QLineSeries>
#include <QtCharts/QAreaSeries>
#include <QRandomGenerator>

#include <QDateTime>
#include <QtCharts/QHXYModelMapper>
#include <QTimer>

#include "boost/range/irange.hpp"

QT_CHARTS_USE_NAMESPACE


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    auto *upper = new QLineSeries;
    auto *lower = new QLineSeries;
    auto *generator = QRandomGenerator::global();

    const auto maxSamples = 10000;

    for(auto x : boost::irange(0, maxSamples))
    {
        lower->append(QPointF(x, 0));
        upper->append(QPointF(x, generator->bounded(0, 100)));
    }

    auto *series = new QAreaSeries(upper, lower);

    QChart *chart = new QChart();
    chart->addSeries(series);
    chart->createDefaultAxes();
    chart->legend()->setVisible(false);

    chart->axisY(series)->setRange(0, 100);

    QChartView *chartView = new QChartView(chart);
    //chartView->setRenderHint(QPainter::Antialiasing);

    QMainWindow window;
    window.setCentralWidget(chartView);
    window.resize(800, 600);
    window.show();

    return a.exec();
}


Any ideas what could be the problem here?

1

There are 1 answers

0
litguy On

We have bounced into this times ago and found that the implementation of append() in a QXYSeries was suboptimal and was consuming a lot of time with large datasets.

To improve the performance, we now use:

  void QXYSeries::replace(QVector<QPointF> points)

with a local vector that we first allocate to the dataset size, and then fill with the actual data.

With large datasets, you may still have performance issues, depending on the type of series, due to the construction of the graphics items used to render the series.