QCustomPlot Discussion and Comments

How scroll from right to left without changing the X-axisReturn to overview


https://www.qcustomplot.com/index.php/demos/realtimedatademo
I want the effect to be like this demo but keep the X-axis unchanged during the curve scrolling, and only keep and display the latest 1 screen of data, and delete the old data from the left side of the screen.

                                                    (x0,y0) //first
			               (x-1,y0) (x0,y1) //2
		          (x-1,y0) (x-1,y1) (x0,y2) //3
             (x-3,y1) (x-2,y0) (x-1,y2) (x0,y3) //4
(x-4,y0) (x-3,y1) (x-2,y2) (x-1,y3) (x0,y4) //5
(x-4,y1) (x-3,y2) (x-2,y3) (x-1,y4) (x0,y5) //6
...
(x-4,y95) (x-3,y96) (x-2,y97) (x-1,y98) (x0,y99) //100
...
(x-4,yn-3) (x-3,yn-3) (x-2,yn-3) (x-1,yn-2) (x0,yn-1) //n-th

thanks

#include "qcustomplot.h"
#include <QApplication>
#include <QObject>
#include <QTimer>
#include <QQueue>
#include <QRandomGenerator>

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

    QCustomPlot *plot = new QCustomPlot();
    plot->setWindowTitle("QCustomPlot Roll Demo");
    plot->resize(800, 600);
    plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
    plot->setInteraction (QCP::iSelectPlottables, true);
    plot->yAxis->setRange(-10,10);
    plot->show();
    plot->setNoAntialiasingOnDrag(true);

    auto graph = plot->addGraph();
    graph->setPen(QPen(Qt::blue));
    graph->setLineStyle(QCPGraph::lsLine);
    graph->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCross, 8));

    qint32 bufferSize = 100;
    QQueue<double> XQueue,YQueue;
    QTimer t1;
    QObject::connect(&t1, &QTimer::timeout, plot, [&](){
        if (XQueue.size() <= bufferSize) XQueue.prepend(-XQueue.size());
        if (YQueue.size() > bufferSize) YQueue.dequeue();
        YQueue.enqueue(QRandomGenerator::global()->bounded(-5, 5));

        if(plot->xAxis->range().upper) plot->xAxis->setRange(-bufferSize, 0);
        plot->graph()->setData(XQueue.toVector(),YQueue.toVector(), true);
        plot->replot(QCustomPlot::rpQueuedReplot);
    });

    QRadioButton* btn = new QRadioButton("Start/Stop", plot);
    btn->move(380, 0);
    btn->show();
    QObject::connect(btn, &QRadioButton::clicked, plot, [&](bool on){
        if(on) {
            XQueue.clear();
            YQueue.clear();
            t1.start(100);
        }else{
            t1.stop();
        }
    });

    return app.exec();
}

I try it, please give some suggestions